|   | php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login | 
| 
  [2008-02-18 18:07 UTC] uwendel at mysql dot com
 Description: ------------ The PHP manual states that PDO->errorCode() returns the SQLSTATE associated with the last operation run on the handle, http://www.php.net/manual/en/function.PDO-errorCode.php "Return Values Returns a SQLSTATE, a five-character alphanumeric identifier defined in the ANSI SQL-92 standard. Briefly, an SQLSTATE consists of a two-character class value followed by a three-character subclass value. A class value of 01 indicates a warning and is accompanied by a return code of SQL_SUCCESS_WITH_INFO. Class values other than '01', except for the class 'IM', indicate an error. The class 'IM' is specific to warnings and errors that derive from the implementation of PDO (or perhaps ODBC, if you're using the ODBC driver) itself. The subclass value '000' in any class indicates that there is no subclass for that SQLSTATE. " What is PDO->errorCode() supposed to return if no operation has been run on the handle yet? If its valid to return any empty string, please add this to the documentation. Reproduce code: --------------- nixnutz@ulflinux:~/php53> sapi/cli/php -r '$pdo=new PDO("mysql:dbname=phptest;unix_socket=/tmp/mysql.sock", "root", "root"); var_dump($pdo->errorCode());' string(0) "" nixnutz@ulflinux:~/php53> sapi/cli/php -r '$pdo=new PDO("sqlite:/tmp/foo.db"); var_dump($pdo->errorCode());' string(0) "" Expected result: ---------------- Its a matter of taste. Personally I have a preference for returning '00000' as this makes checking the error code easier but this would be sort of a BC break. Actual result: -------------- Empty string (see above). PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits             | |||||||||||||||||||||||||||
|  Copyright © 2001-2025 The PHP Group All rights reserved. | Last updated: Fri Oct 31 19:00:02 2025 UTC | 
The patch below allows you to do: $error = $pdo->errorCode(); if (is_null($error)) { // There's an empty error... } http://dev.agoraproduction.com/php/5_3/ext/pdo/bug44153.patch More I look at it and more I think we should have a generic message like "UNUSED" or something similar but I think NULL is also quite straightforward.