Bug #64705 [Opn->Ver]: errorInfo property of PDOException is null when PDO::__construct() fails
| From: | mbeccati@php.net | Date: | Wed, 04 Jun 2014 09:12:31 +0000 |
| Subject: | Bug #64705 [Opn->Ver]: errorInfo property of PDOException is null when PDO::__construct() fails | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-186049@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=64705&edit=1
ID: 64705
Updated by: mbeccati@php.net
Reported by: christian dot lawrence at calorieking dot com
Summary: errorInfo property of PDOException is null when
PDO::__construct() fails
-Status: Open
+Status: Verified
Type: Bug
-Package: PDO PgSQL
+Package: PDO Core
PHP Version: 5.3.24
Block user comment: N
Private report: N
New Comment:
I started writing a new common phpt file in order to check the behaviour of drivers other then pgsql
and it seems that pdo_sqlite and pdo_mysql are affected too, so I'm changing the bug type to
PDO Core.
Previous Comments:
------------------------------------------------------------------------
[2013-04-24 17:11:36] christian dot lawrence at calorieking dot com
Description:
------------
PDO::__construct() will always throw a PDOException if the connection fails regardless of which
PDO::ATTR_ERRMODE is currently set. The PDOException has a public property $errorInfo which
corresponds to PDO::errorInfo() or PDOStatement::errorInfo().
When PDO::__construct() throws a PDOException say, because of a database server issue, the public
property PDOException::$errorInfo is set to NULL and the return value from PDOException::getCode()
is not the expected string SQLSTATE error code.
I would have expected a non-NULL PDOException::$errorInfo to be set when the exception is caught.
Test script:
---------------
<?php
// Valid DSN, but with wrong password to trigger the exception
$dsn = 'pgsql:host=localhost;dbname=test;user=foo;password=wrongpass';
try {
$pdo = new \PDO($dsn, null, null);
} catch (\PDOException $e) {
var_dump($e->errorInfo);
var_dump($e->getCode());
var_dump($e->getMessage());
}
?>
Expected result:
----------------
array(3) {
[0] =>
string(5) "08006"
[1] =>
int(7)
[2] =>
string(53) "FATAL: password authentication failed for user "foo""
}
string(5) "08006"
string(73) "SQLSTATE[08006] [7] FATAL: password authentication failed for user
"foo""
Actual result:
--------------
NULL
int(7)
string(73) "SQLSTATE[08006] [7] FATAL: password authentication failed for user
"foo""
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=64705&edit=1