我在使用 zend multidb 时遇到了一些问题。我的适配器没有被切换,我设置为默认值的适配器每次都被使用。而且它也没有给我任何错误。以下是我用于 zend multidb 功能的代码。
引导程序.php
public function _initDB()
{
Zend_Registry::getInstance();
$this->bootstrap('multidb');
$multidb = $this->getPluginResource('multidb');
Zend_Registry::set('dbR', $multidb->getDb('dbR'));
Zend_Registry::set('dbW', $multidb->getDb('dbW'));
}
应用程序.ini
resources.multidb.dbR.adapter = "mysqli"
resources.multidb.dbR.host = "xxx.xxx.x.xx"
resources.multidb.dbR.username = "root"
resources.multidb.dbR.password = "admin"
resources.multidb.dbR.dbname = "test_app1"
resources.multidb.dbR.profiler = "false"
resources.multidb.dbR.isDefaultTableAdapter = "true"
resources.multidb.dbW.adapter = "mysqli"
resources.multidb.dbW.host = "xxx.xxx.x.xx"
resources.multidb.dbW.username = "root"
resources.multidb.dbW.password = "admin"
resources.multidb.dbW.dbname = "test_app2"
现在在我的模型类中,我使用以下代码行来执行任何写操作
class Abc_Model_ModelName extends Zend_Db_Table_Abstract
{
protected $_dbR;
protected $_dbW;
protected $_name = 'table_name';
public function init(){
$this->_dbR = Zend_Registry::get("dbR");
$this->_dbW = Zend_Registry::get("dbW");
}
public function addedit($data = array())
{
$this->setDefaultAdapter($this->_dbW);
}
}
谁能帮我解决这个问题?