From: uwendel at mysql dot com Operating system: Linux PHP version: 5.3CVS-2008-02-18 (CVS) PHP Bug Type: PDO related Bug description: PDO->errorInfo() does not always return three element array
Description: ------------ According to the manual one can expect PDO->errorInfo() to return an array with three elements. "Return Values PDO->errorInfo() returns an array of error information about the last operation performed by this database handle. The array consists of the following fields: Element Information 0 SQLSTATE error code (a five-character alphanumeric identifier defined in the ANSI SQL standard). 1 Driver-specific error code. 2 Driver-specific error message." http://www.php.net/manual/en/function.PDO-errorInfo.php The manual is wrong. PDO will not always return an array with three elements. There are two situations when you will get an array with only one element. 1) driver has not set an error code yet 2) IM001 - not implemented (= driver can't set an error code) I'd appreciate if you either document this or fix PDO->errorInfo() to always return an array with three elements. My personal preference is change PDO->errorInfo(). I don't see any reason why people would have to use a complicated test like the following to avoid "undefined index" style messages: if (count($info = $pdo->errorInfo()) == 3) die(sprintf("SQLSTATE %s, Driver info: %s/%s", $info[0], $info[1], $info[2])); else die(sprintf("SQLSTATE %s", $info[0])); Note that this bug is somewhat related to the question raised in http://bugs.php.net/bug.php?id=44153 . Reproduce code: --------------- [EMAIL PROTECTED]:~/php53> sapi/cli/php -r '$pdo=new PDO("sqlite:/tmp/foo.db"); var_dump($pdo->errorCode()); var_dump($pdo->errorInfo());' string(0) "" array(1) { [0]=> string(0) "" } [EMAIL PROTECTED]:~/php53> sapi/cli/php -r '$pdo=new PDO("mysql:dbname=phptest;unix_socket=/tmp/mysql.sock", "root", "root"); $pdo->getAttribute(-1); var_dump($pdo->errorCode()); var_dump($pdo->errorInfo());' Warning: PDO::getAttribute(): SQLSTATE[IM001]: Driver does not support this function: driver does not support that attribute in Command line code on line 1 string(5) "IM001" array(1) { [0]=> string(5) "IM001" } [EMAIL PROTECTED]:~/php53> sapi/cli/php -r '$pdo=new PDO("sqlite:/tmp/foo.db"); $pdo->getAttribute(-1); var_dump($pdo->errorCode()); var_dump($pdo->errorInfo());' Warning: PDO::getAttribute(): SQLSTATE[IM001]: Driver does not support this function: driver does not support that attribute in Command line code on line 1 string(5) "IM001" array(1) { [0]=> string(5) "IM001" } Expected result: ---------------- Always return an array with three elements. Make checking the errorInfo() easier. Actual result: -------------- See above. Array with only one element. -- Edit bug report at http://bugs.php.net/?id=44154&edit=1 -- Try a CVS snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=44154&r=trysnapshot52 Try a CVS snapshot (PHP 5.3): http://bugs.php.net/fix.php?id=44154&r=trysnapshot53 Try a CVS snapshot (PHP 6.0): http://bugs.php.net/fix.php?id=44154&r=trysnapshot60 Fixed in CVS: http://bugs.php.net/fix.php?id=44154&r=fixedcvs Fixed in release: http://bugs.php.net/fix.php?id=44154&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=44154&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=44154&r=needscript Try newer version: http://bugs.php.net/fix.php?id=44154&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=44154&r=support Expected behavior: http://bugs.php.net/fix.php?id=44154&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=44154&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=44154&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=44154&r=globals PHP 4 support discontinued: http://bugs.php.net/fix.php?id=44154&r=php4 Daylight Savings: http://bugs.php.net/fix.php?id=44154&r=dst IIS Stability: http://bugs.php.net/fix.php?id=44154&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=44154&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=44154&r=float No Zend Extensions: http://bugs.php.net/fix.php?id=44154&r=nozend MySQL Configuration Error: http://bugs.php.net/fix.php?id=44154&r=mysqlcfg