ID: 35202 User updated by: lists at zaunere dot com Reported By: lists at zaunere dot com -Status: Bogus +Status: Open Bug Type: PDO related Operating System: Windows XP PHP Version: 5.1.0RC4 Assigned To: wez New Comment:
The function prototypes in both of these locations is wrong: http://us2.php.net/manual/en/function.pdo-errorcode.php http://us2.php.net/manual/en/function.pdostatement-errorcode.php Integers are not returned as indicated in the documented function prototypes. Furthermore, there is some inconsistency in how '00000' is returned. It would be expected that '00000' is always returned, or that an invalid statement prepare would return an error. Code ---- $pdo = new PDO('mysql:dbname=oet;host=localhost','me','you'); echo ' new pdo (good connection)=> '; var_dump($pdo->errorCode()); $stmt = $pdo->prepare('SELECT * FROM Valid'); echo ' stmt prepare (valid table)=> '; var_dump($stmt->errorCode()); $stmt->execute(); echo ' stmt execute (valid table)=> '; var_dump($stmt->errorCode()); $stmt1 = $pdo->prepare('SELECT * FROM Invalid'); echo 'stmt1 prepare (invalid table)=> '; var_dump($stmt1->errorCode()); $stmt1->execute(); echo 'stmt1 execute (invalid table)=> '; var_dump($stmt1->errorCode()); $stmt2 = $pdo->prepare('INVALID SQL'); echo ' stmt2 prepare (invalid SQL)=> '; var_dump($stmt2->errorCode()); $stmt2->execute(); echo ' stmt2 execute (invalid SQL)=> '; var_dump($stmt2->errorCode()); Output ------ new pdo (good connection)=> string(5) "00000" stmt prepare (valid table)=> string(0) "" stmt execute (valid table)=> string(5) "00000" stmt1 prepare (invalid table)=> string(0) "" stmt1 execute (invalid table)=> string(5) "HY000" stmt2 prepare (invalid SQL)=> string(0) "" stmt2 execute (invalid SQL)=> string(5) "HY000" Only the execute() appears to set errorCode(), whereas the documents say "the last operation on the statement handle." Thanks, Hans Previous Comments: ------------------------------------------------------------------------ [2005-11-13 13:37:14] [EMAIL PROTECTED] errorCode() returns a SQLSTATE string, as documented. Use errorInfo() to obtain driver specific error information. ------------------------------------------------------------------------ [2005-11-12 20:13:41] [EMAIL PROTECTED] SQL error codes are strings ------------------------------------------------------------------------ [2005-11-12 20:11:20] lists at zaunere dot com Description: ------------ The errorCode() method of both the PDO and PDOStatement objects return a string, rather than an integer, as documented. If there is no error, they return an empty string. Reproduce code: --------------- $stmt = $MyPDO->prepare('SELECT * FROM MyTable'); var_dump($stmt->errorCode()); Expected result: ---------------- int(0) Actual result: -------------- string(0) "" ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=35202&edit=1