ZF-51: Missing error handling in _connect() (TRAC#74)

Issue Type: Bug Created: 2006-06-20T01:04:48.000+0000 Last Updated: 2007-07-05T14:44:27.000+0000 Status: Closed Fix version(s): - 0.1.4 (29/Jun/06)

Reporter: Zend Framework (zend_framework) Assignee: Mark Evans (sparky) Tags: - Zend_Db

Related issues: Attachments: - ZF-51.patch


File : Zend_Db_Adapter_Pdo_Abstract.php Function: protected function _connect() Line : 78 $this->_connection = new PDO(

    $this->_dsn(), $this->_config['username'], $this->_config['password'] );

If the connection fails due to uncaught exception, it would dump a plethora of info (as per the docs) onto the client browser including the connection details such as userid/password... (and what not?) for the world wild web to see.


try {

    $dbh = new PDO('mysql:host=localhost;dbname=test', $user, $pass); foreach ($dbh->query('SELECT * from FOO') as $row) {


    } $dbh = null; } catch (PDOException $e) { print "Error!: " . $e->getMessage() . "<br/>"; die(); }


Posted by Mark Evans (sparky) on 2006-06-21T17:46:42.000+0000

Here is a patch to wrap the PDO connection in a try / catch.

Posted by Mark Evans (sparky) on 2006-06-22T05:30:24.000+0000

New patch which removed the need for exit;

Posted by Ralph Schindler (ralph) on 2006-06-22T10:06:56.000+0000

Personally, I would like to see you catch the PDOException and throw a Zend_Db_Exception. I would also pick out some of the most useful, common errors from using PDO errors via the errorCode, then put the text of those errors (or nicely re-written error) in as the string of the Zend_Db_Exception.

Basically Zend_Db_Exception needs to be a pretty interface to all db exceptions, with the added ability to be able to drill down into the Exception thrown by the internal Adapter. This means adding 2 methods, perhaps getAdapterMessage() & getAdapterCode() to be able to get the exact error code from the given internal adapter.

my 2 cents.


Posted by Mark Evans (sparky) on 2006-06-22T16:16:19.000+0000

Add a try / catch and throw a Zend_Db_Adapter_Exception on failure

Have you found an issue?

See the Overview section for more details.


© 2006-2018 by Zend, a Rogue Wave Company. Made with by awesome contributors.

This website is built using zend-expressive and it runs on PHP 7.