|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull Requests
Pull requests:
HistoryAllCommentsChangesGit/SVN commits
[2014-01-01 12:32 UTC] felipe@php.net
-Package: PDO related
+Package: PDO PgSQL
[2014-06-04 09:12 UTC] mbeccati@php.net
-Status: Open
+Status: Verified
-Package: PDO PgSQL
+Package: PDO Core
[2014-06-04 09:12 UTC] mbeccati@php.net
[2017-10-24 08:29 UTC] kalle@php.net
-Package: PDO Core
+Package: PDO related
[2019-02-17 22:36 UTC]
[2020-08-10 13:28 UTC] corey dot taylor dot fl at gmail dot com
[2020-08-11 15:16 UTC] nikic@php.net
[2020-08-11 15:16 UTC] nikic@php.net
-Status: Verified
+Status: Closed
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Thu Oct 30 17:00:01 2025 UTC |
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""