I'm attempting to use PHP5 RC1 and the PEAR DB class with the mysqli driver to implement prepared statements that are passed to a MySQL 4.1.1 installation. The problem is that strings passed in prepared statements do not appear in the database (i.e. fields are NULL), although integer values do.
For example, suppose I have a simple table like:
[ID] int (primary key, auto increment)
[Age] int
[Name] varchar
Then using PEAR:😃B:
$stmt = $db->prepare("INSERT INTO Tablename VALUES('', ?, ?)");
$db->execute($stmt, array(1, 'Michael'));
This will not work correctly. When I view the database, the Age field will have been filled in with a 1, but the varchar field Name will be blank. Everything works fine if I define the values in the actual query string itself and use $db->query().
On the other hand, creating a handle $mysqli = new mysqli() and using prepared statements works fine.
$stmt = $mysqli->prepare("INSERT INTO Tablename VALUES('', ?, ?)");
$stmt->bind_param('is', $age, $name);
$age = 1;
$name = 'Michael';
$stmt->execute();
No problems at all there.
I notice raw mysqli has me specify the datatype for each field in the bind_param() call. I did not see any similar requirement with PEAR:😃B.
Has anyone else experimented with this yet? Thanks for any help.
Abiel