ID:               44154
 Updated by:       [EMAIL PROTECTED]
 Reported By:      uwendel at mysql dot com
-Status:           Open
+Status:           To be documented
 Bug Type:         PDO related
 Operating System: Linux
 PHP Version:      5.3CVS-2008-02-18 (CVS)
 New Comment:

This bug has been fixed in CVS.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
http://snaps.php.net/.
 
Thank you for the report, and for helping us make PHP better.

Ok I have applied the patch to 5_3 and HEAD. 


Previous Comments:
------------------------------------------------------------------------

[2008-11-01 13:52:55] [EMAIL PROTECTED]

I have a very small patch that I could commit if someone else agrees.

http://dev.agoraproduction.com/php/5_3/ext/pdo/bug44154.patch

------------------------------------------------------------------------

[2008-02-18 18:25:09] uwendel at mysql dot com

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 this bug report at http://bugs.php.net/?id=44154&edit=1

Reply via email to