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->errorCode() returns '' instead of SQLSTATE if no 
operation has been run

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 bug report at http://bugs.php.net/?id=44153&edit=1
-- 
Try a CVS snapshot (PHP 5.2): 
http://bugs.php.net/fix.php?id=44153&r=trysnapshot52
Try a CVS snapshot (PHP 5.3): 
http://bugs.php.net/fix.php?id=44153&r=trysnapshot53
Try a CVS snapshot (PHP 6.0): 
http://bugs.php.net/fix.php?id=44153&r=trysnapshot60
Fixed in CVS:                 http://bugs.php.net/fix.php?id=44153&r=fixedcvs
Fixed in release:             
http://bugs.php.net/fix.php?id=44153&r=alreadyfixed
Need backtrace:               http://bugs.php.net/fix.php?id=44153&r=needtrace
Need Reproduce Script:        http://bugs.php.net/fix.php?id=44153&r=needscript
Try newer version:            http://bugs.php.net/fix.php?id=44153&r=oldversion
Not developer issue:          http://bugs.php.net/fix.php?id=44153&r=support
Expected behavior:            http://bugs.php.net/fix.php?id=44153&r=notwrong
Not enough info:              
http://bugs.php.net/fix.php?id=44153&r=notenoughinfo
Submitted twice:              
http://bugs.php.net/fix.php?id=44153&r=submittedtwice
register_globals:             http://bugs.php.net/fix.php?id=44153&r=globals
PHP 4 support discontinued:   http://bugs.php.net/fix.php?id=44153&r=php4
Daylight Savings:             http://bugs.php.net/fix.php?id=44153&r=dst
IIS Stability:                http://bugs.php.net/fix.php?id=44153&r=isapi
Install GNU Sed:              http://bugs.php.net/fix.php?id=44153&r=gnused
Floating point limitations:   http://bugs.php.net/fix.php?id=44153&r=float
No Zend Extensions:           http://bugs.php.net/fix.php?id=44153&r=nozend
MySQL Configuration Error:    http://bugs.php.net/fix.php?id=44153&r=mysqlcfg

Reply via email to