我想从多个数据库中获取查询,我试图连接两个数据库(database1,database2)我已经定义了
的的application.ini :
resources.multidb.db1.adapter = "PDO_MYSQL"
resources.multidb.db1.params.host = 'localhost'
resources.multidb.db1.params.username = 'root'
resources.multidb.db1.params.password = ''
resources.multidb.db1.params.dbname = 'database1'
resources.multidb.db1.isDefaultTableAdapter = true
resources.multidb.db2.adapter = "PDO_MYSQL"
resources.multidb.db2.params.host = 'localhost'
resources.multidb.db2.params.username = 'root'
resources.multidb.db2.params.password = ''
resources.multidb.db2.params.dbname = 'database2'
我已将以下代码添加到 Bootstrap.php :
protected function _initDbAdapter()
{
$resource = $this->getPluginResource('multidb');
$resource->init();
$db1 = $resource->getDb('db1');
$db2 = $resource->getDb('db2');
Zend_Registry::set('db1', $db1);
Zend_Registry::set('db2', $db2);
}
在模型中..我已经为db2的get查询定义了 File.php :
<?php
class Model_file extends Zend_Db_Table_Abstract
{
protected $_name = 'file';
protected $_schema = 'db2';
}
和db1的Model_Books
<?php
class Model_Books extends Zend_Db_Table_Abstract
{
protected $_name = 'subscriber';
protected $_schema = 'db1';
}
控制器中的我有这个:
$fileModel = new Model_file();
$select = $fileModel->select();
$booksModel = new Model_Books();
$select = $booksModel->select();
但我收到此错误:
致命错误:未捕获的异常&#39; Zend_Db_Adapter_Exception&#39;带有消息&#39;配置数组必须有一个用于&#39; dbname&#39;的键。命名数据库实例&#39;
我该如何解决?