Skip navigation.

PDO beta revisited

PDO is the new database layer that will be released in PHP 5.1. Today I downloaded the latest version of the PHP5.1 beta from snaps.php.net and tested PDO again for compatibility with ADOdb, the PHP database library i maintain. Then i compared the results with my last serious test in July 2005. In general, I find PDO remains in early beta state (functionality documented, but bits are not implemented).

One of my previous complaints was that binding did not work. I was worried that it was a coding problem on my part, but apparently that was not the case: the same code that failed in July works fine now, but there are still some glitches. The following works (using adodb syntax):

 $rs = $db->Execute("select * from table where a=? and b=?",array(1,2));

However binding doesn't work as expected with associative arrays:

 $rs = $db->Execute("select * from table where a=? and b=?",array('a'=>1,'b'=>2));

I get this error message:Warning: PDOStatement::execute() [function.execute]: SQLSTATE[HY093]: Invalid parameter number: parameter was not defined in ...

I think this should be supported, as extensions such as mssql and pgsql allow positional bind parameters to support associative arrays.

Some of the other problems I listed in the July still exist:

  • The pgsql and mssql drivers do not support switching between autocommit and commit/rollback. So all statements are autocommited.
  • The oci (for Oracle) and mssql drivers do not support getColumnMeta(), so checking field types and names dynamically is not possible at run-time.

PS: I haven't filed a bug report (too busy - as you can see from my infrequent posts), so if someone could do so, it would be nice.

PPS: The version of PHP i downloaded: PHP 5.1.0RC5-dev (built: Nov 11 2005 00:23:52)

Update: 17 Nov 2005

A quick response to this. A large number of the bugs reported to bugs.php.net are ignored, not replicated, misunderstood. This often is not the fault of the bug fixer, but because the bug reporter needs to produce a concise, clear example. Doing so is not easy.

I don't have the time (=== laziness) to strip off all the adodb cruft and produce a nice PDO example that is totally unambigious. So to blame me for not posting a bug report is entirely correct. However we all need to be open to all avenues of input. See no evil, hear no evil, say no evil, netevil?

Here's what is happening:

Suppose you are reading an array from somewhere, and you want to update a database with the values of the array. You don't know whether the array to be passed to you is numeric or associative. Hey it's a library function!! Given that associative arrays are fixed in position, it's still valid in PHP4 to do this:

function update($arr)
{
global $db;

   $db->Execute('update table set a=?, b=? where c=?',$arr);
}

This function will work in PHP4 with

update(array(1,2,3));
update(array('z'=>1,3,4));

With PDO, that is not possible.

New: Kynx points out that the above works fine with older versions of PDO. I forgot about that. I presume something changed when binding was properly implemented more recently. It is possible, depending on it was implemented in PDO, that the above functionality is permanently broken or obsolete.