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
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
@Sergio
At my company we have this problems too, I found a work around at http://framework.zend.com/issues/browse/ZF-12466
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.