ZF-9615: getDbAdapter() on Zend_Application_Resource_Db incorrect behaviour

Description

From Zend Application Available Resources Db Documentation:

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


[production]
resources.db.adapter = "pdo_mysql"
resources.db.params.host = "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:


$resource = $bootstrap->getPluginResource('db');

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


$db = $resource->getDbAdapter();

{quote}

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


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:


function _initDb() {
    if ($this->hasPluginResource('db')) {
        $resource = $this->getPluginResource('db');
        $db = $resource->init();
        return $db;
    }
}

Comments

What exactly is the problem?

Sorry, clicked on Create before i had finished writing.

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.

Merged to trunk and 1.12 branch.

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?

@Sergio

At my company we have this problems too, I found a work around at http://framework.zend.com/issues/browse/ZF-12466

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

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

Also thank you Arnold for the workaround advice.