Req #61040 [Opn->Nab]: PDOException::getCode() returns SQLSTATE instead of error code
Edit report at https://bugs.php.net/bug.php?id=61040&edit=1
ID: 61040
Updated by: rasmus@php.net
Reported by: jjgmeijer at hotmail dot com
Summary: PDOException::getCode() returns SQLSTATE instead of
error code
-Status: Open
+Status: Not a bug
Type: Feature/Change Request
Package: PDO related
Operating System: Linux
PHP Version: 5.3SVN-2012-02-10 (SVN)
Block user comment: N
Private report: N
New Comment:
But the error code is not portable in any way and PDO tries to normalize the
interface to the databases, so I think returning the SQLSTATE is more useful here
from a portability perspective. The error code is still shown as part of
getMessage() and you have it separated out in PDOException::errorInfo where you
get the SQLSTATE, the error code and the error text message in 3 separate
elements so if your app needs to dig beyond the standard ANSI SQL codes it can
quite easily.
Previous Comments:
------------------------------------------------------------------------
[2012-02-10 11:22:01] jjgmeijer at hotmail dot com
Description:
------------
PDOException::getCode() returns the SQLSTATE instead of the error code.
For example a var_dump of a random PDOException:
object(PDOException)[97]
protected 'message' => string 'SQLSTATE[40001]: Serialization failure: 1213
Deadlock found when trying to get lock; try restarting transaction' (length=111)
private 'string' (Exception) => string '' (length=0)
protected 'code' => string '40001' (length=5)
then the 'code' should not be the SQLSTATE (40001) but the error code (1213). My
reason for this is that the SQLSTATE may not be unique, the error code is.
For more info: http://dev.mysql.com/doc/refman/5.5/en/error-messages-server.html
Test script:
---------------
Try to get a random PDOException with an invalid query.
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=61040&edit=1
Thread (2 messages)