From:             christian dot lawrence at calorieking dot com
Operating system: 
PHP version:      5.3.24
Package:          PDO related
Bug Type:         Bug
Bug description:errorInfo property of PDOException is null when 
PDO::__construct() fails

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

Reply via email to