Zend multidb连接失败

时间:2012-03-23 10:48:12

标签: zend-framework

您好我正在尝试连接我的zend框架应用程序中的两个数据库。

以下是local.ini文件中的databalse设置。

resources.multidb.core.adapter = "pdo_mysql"
resources.multidb.core.params.host = "hostname"
resources.multidb.core.params.username = "root"
resources.multidb.core.params.password = "pwd"
resources.multidb.core.params.dbname = "coredb"
resources.multidb.core.isDefaultTableAdapter = true

resources.multidb.app.adapter = "pdo_mysql"
resources.multidb.app.params.host = "hostname"
resources.multidb.app.params.username = "roor"
resources.multidb.app.params.password = "iamroot123"
resources.multidb.app.params.dbname = "appdb"
resources.multidb.app.isDefaultTableAdapter = false

我在bootstarp中的代码如下。

public function _initDbRegistry()
{
    $this->bootstrap('multidb');
    $resource = $this->getPluginResource('multidb');
    Zend_Registry::set('dbCore', $resource->getDb('core'));
    Zend_Registry::set('dbOlap', $resource->getDb('app'));
}

但是当我尝试访问我的应用程序时,我收到以下错误。

Fatal error: Uncaught exception 'Zend_Db_Adapter_Exception' with message 'Configuration array must have a key for 'dbname' that names the database instance' in C:\xampp\zend\library\Zend\Db\Adapter\Abstract.php:287 Stack trace: #0 C:\xampp\zend\library\Zend\Db\Adapter\Abstract.php(183): Zend_Db_Adapter_Abstract->_checkRequiredOptions(Array) #1 C:\xampp\zend\library\Zend\Db.php(270): Zend_Db_Adapter_Abstract->__construct(Array) #2 C:\xampp\zend\library\Zend\Application\Resource\Multidb.php(99): Zend_Db::factory('pdo_mysql', Array) #3 C:\xampp\zend\library\Zend\Application\Bootstrap\BootstrapAbstract.php(683): Zend_Application_Resource_Multidb->init() #4 C:\xampp\zend\library\Zend\Application\Bootstrap\BootstrapAbstract.php(626): Zend_Application_Bootstrap_BootstrapAbstract->_executeResource('multidb') #5 C:\xampp\zend\library\Zend\Application\Bootstrap\BootstrapAbstract.php(586): Zend_Application_Bootstrap_BootstrapAbstract->_bootstrap(NULL) #6 C:\xampp\zend\library\Zend\Application.php(355): Zend_Application_Bootstrap_Boo in C:\xampp\zend\library\Zend\Db\Adapter\Abstract.php on line 287

我无法理解出了什么问题。有人能帮我吗?另请告诉我如何在模型类中使用db对象。

非常感谢。

1 个答案:

答案 0 :(得分:4)

查看文档Multidb Example #14你application.ini可能不正确试试这个(删除:params):

resources.multidb.core.adapter = "pdo_mysql"
resources.multidb.core.host = "hostname"
resources.multidb.core.username = "root"
resources.multidb.core.password = "pwd"
resources.multidb.core.dbname = "coredb"
resources.multidb.core.isDefaultTableAdapter = true

resources.multidb.app.adapter = "pdo_mysql"
resources.multidb.app.host = "hostname"
resources.multidb.app.username = "roor"
resources.multidb.app.password = "iamroot123"
resources.multidb.app.dbname = "appdb"
resources.multidb.app.isDefaultTableAdapter = false