ID: 44153 Updated by: [EMAIL PROTECTED] Reported By: uwendel at mysql dot com Status: Open Bug Type: PDO related Operating System: Linux PHP Version: 5.3CVS-2008-02-18 (CVS) New Comment:
What about returning NULL ? You could easily check the results using is_null() and if it's null that means there's no errorCode(). Whereas when there's an error code you'll get the usual sqlstate message/code. What do you think? I think NULL would make great sense. Previous Comments: ------------------------------------------------------------------------ [2008-02-18 18:07:53] 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: --------------- [EMAIL PROTECTED]:~/php53> sapi/cli/php -r '$pdo=new PDO("mysql:dbname=phptest;unix_socket=/tmp/mysql.sock", "root", "root"); var_dump($pdo->errorCode());' string(0) "" [EMAIL PROTECTED]:~/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). ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=44153&edit=1