对于该版本的 Magento (1.3.2.4),您需要在 config.xml 文件中指定读写连接。
在 下<global>
,添加一个<resources>
节点,如下所示:
<resources>
<yourModelNode_write>
<connection>
<use>core_write</use>
</connection>
</yourModelNode_write>
<yourModelNode_read>
<connection>
<use>core_write</use>
</connection>
</yourModelNode_read>
</resources>
确保刷新缓存!
这种类型的配置在以后的 Magento 版本中是可选的;如果您未在配置中指定它们,系统将加载默认的读/写连接。我不确定这个特性是什么时候实现的,但它存在于 1.6.x 中。
1.3.2.4 和 1.6.x 的区别在于 Mage_Core_Model_Resource::getConnection()。
如果您的 config.xml 中没有指定,1.6.x 将返回默认的读/写连接:
Mage_Core_Model_Resource::getConnection()
$connConfig = Mage::getConfig()->getResourceConnectionConfig($name);
if (!$connConfig) {
$this->_connections[$name] = $this->_getDefaultConnection($name);
return $this->_connections[$name];
}
1.3.2.4 将返回 false:
$connConfig = Mage::getConfig()->getResourceConnectionConfig($name);
if (!$connConfig || !$connConfig->is('active', 1)) {
return false;
}
您收到“未实现 Zend_Db_Adapter_Abstract”错误的原因位于 Varien_Data_Collection_Db::setConnection() 中:
public function setConnection($conn)
{
if (!$conn instanceof Zend_Db_Adapter_Abstract) {
throw new Zend_Exception('dbModel read resource does not implement Zend_Db_Adapter_Abstract');
}
$this->_conn = $conn;
$this->_select = $this->_conn->select();
}
当false
作为连接 ($conn) 传入时,它会抛出这个错误,因为——当然——false
不是 Zend_Db_Adapter_Abstract 的实例。