我在使用zend multidb時遇到了一些問題。我的適配器沒有被切換,而且我設置爲默認的每次都在使用。而且它也不會給我任何錯誤。 以下是我用於zend multidb功能的代碼。Zend MultiDB適配器沒有被切換
bootstrap.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'));
}
的application.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);
}
}
任何人都可以幫我解決這個問題嗎?
它不應該是'$此 - > _ dbw-> getAdapter();或 - > getDb()'你可能不想重置你的默認適配器,但你確實想要檢索和第二個適配器的實例。我允許這種情況下的文檔不好,所以我也不確定。 – RockyFord
@RockyFord我已經在我的引導文件中完成了這項工作,並存儲到註冊表中,並在Model類 –