ZF-9615: getDbAdapter() on Zend_Application_Resource_Db incorrect behaviour

Issue Type: Bug Created: 2010-04-04T18:56:25.000+0000 Last Updated: 2012-12-18T20:08:27.000+0000 Status: Resolved Fix version(s): - 1.12.1 (18/Dec/12)

Reporter: Giuseppe Roberti (hardcoded) Assignee: Matthew Weier O'Phinney (matthew) Tags: - Zend_Application_Resource

  • FixForZF1.12
  • zf-caretaker-adamlundrigan

Related issues: - ZF-12466

Attachments: - zend-application-resource-db.patch


From Zend Application Available Resources Db Documentation:

{quote} Below is an example INI configuration that can be used to initialize the DB resource.

<pre class="highlight">
resources.db.adapter = "pdo_mysql" = "localhost"
resources.db.params.username = "webuser"
resources.db.params.password = "XXXXXXX"
resources.db.params.dbname = "test"
resources.db.isDefaultTableAdapter = true

Note: Retrieving the Adapter instance If you choose not to make the adapter instantiated with this resource the default table adapter, how do you retrieve the adapter instance? As with any resource plugin, you can fetch the DB resource plugin from your bootstrap:

<pre class="highlight">
$resource = $bootstrap->getPluginResource('db');

Once you have the resource object, you can fetch the DB adapter using the getDbAdapter() method:

<pre class="highlight">
$db = $resource->getDbAdapter();


So i expect when i override the Application Bootstrap _initDb() function with those:

<pre class="highlight">
function _initDb() {
    if ($this->hasPluginResource('db')) {
        $resource = $this->getPluginResource('db');
        $db = $resource->getDbAdapter();
        return $db;

that everything works fine. But it doesn't because getDbAdapter() does not set the default table adapter; it is acctually setted on init(). Imho, this is the wrong place.

The attached patch should fix this problem.

Here a workaround:

<pre class="highlight">
function _initDb() {
    if ($this->hasPluginResource('db')) {
        $resource = $this->getPluginResource('db');
        $db = $resource->init();
        return $db;


Posted by Dolf Schimmel (Freeaqingme) (freak) on 2010-04-04T19:00:07.000+0000

What exactly is the problem?

Posted by Giuseppe Roberti (hardcoded) on 2010-04-04T19:42:41.000+0000

Sorry, clicked on Create before i had finished writing.

Posted by Dolf Schimmel (Freeaqingme) (freak) on 2010-06-24T18:15:05.000+0000

Reassigning to Matthew.

Matthew, I assume you originally wrote this class? The issue at hand seems legit, but I'm unsure if there's anything I'm missing and/or why you chose to did it the way you did when you wrote it.

Posted by Matthew Weier O'Phinney (matthew) on 2012-11-13T21:38:37.000+0000

Merged to trunk and 1.12 branch.

Posted by Sergio Rinaudo (razorblade) on 2012-11-14T10:53:08.000+0000

After the update this exception is thrown in an application of the company where I work

Uncaught exception 'Zend_Exception' with message 'No entry is registered for key 'pdo_mysql''

It seems to look for a pdo_mysql key inside Zend_Registry. Use temporarily multidb resource instead of db solved the problem.

Is only me with this problem?

Posted by Arnold Pistorius (arnoldpistorius) on 2012-11-14T17:32:50.000+0000


At my company we have this problems too, I found a work around at

Posted by Matthew Weier O'Phinney (matthew) on 2012-11-14T18:31:58.000+0000

Sergio, Arnold -- I've committed a fix that should correct this; let me know if you are still experiencing issues.

Posted by Sergio Rinaudo (razorblade) on 2012-11-15T09:31:46.000+0000

Hello Matthew, everything it's fine with this fix, thank you!

Also thank you Arnold for the workaround advice.

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.