|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #64705 errorInfo property of PDOException is null when PDO::__construct() fails
Submitted: 2013-04-24 17:11 UTC Modified: 2017-10-24 08:29 UTC
Avg. Score:4.0 ± 0.8
Reproduced:3 of 4 (75.0%)
Same Version:0 (0.0%)
Same OS:1 (33.3%)
From: christian dot lawrence at calorieking dot com Assigned:
Status: Verified Package: PDO related
PHP Version: 5.3.24 OS:
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: christian dot lawrence at calorieking dot com
New email:
PHP Version: OS:


 [2013-04-24 17:11 UTC] christian dot lawrence at calorieking dot com
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:

// 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) {


Expected result:
array(3) {
  [0] =>
  string(5) "08006"
  [1] =>
  [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:
string(73) "SQLSTATE[08006] [7] FATAL:  password authentication failed for user "foo""


Add a Patch

Pull Requests

Pull requests:

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2014-01-01 12:32 UTC]
-Package: PDO related +Package: PDO PgSQL
 [2014-06-04 09:12 UTC]
-Status: Open +Status: Verified -Package: PDO PgSQL +Package: PDO Core
 [2014-06-04 09:12 UTC]
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.
 [2017-10-24 08:29 UTC]
-Package: PDO Core +Package: PDO related
 [2019-02-17 22:36 UTC]
The following pull request has been associated:

Patch Name: Fix #64705 PDO driver constructor throw PDOException but not setting errorInfo
On GitHub:
PHP Copyright © 2001-2020 The PHP Group
All rights reserved.
Last updated: Sat Aug 08 08:01:23 2020 UTC