我正在尝试使用Zend Framework连接到多个数据库。当我使用与mysql_connect相同的凭据进行连接时,它可以正常工作。当我与Zend连接时,我得到了
"Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[28000] [1045] Access
denied for user 'xxxx'@'localhost' (using password: YES)' in C:\wamp\www\zend\library\Zend\Db\Adapter\Pdo\Abstract.php on line 144"
我在http://www.amazium.com/blog/using-different-databases-with-zend-framework
上关注了教程这是我的application.ini:
resources.multidb.db1.adapter = "PDO_MYSQL"
resources.multidb.db1.dbname = "xxxxx"
resources.multidb.db1.username = "xxxxxx"
resources.multidb.db1.password = "xxxxxx"
resources.multidb.db1.hostname = "localhost"
resources.multidb.db1.charset = "UTF8"
resources.multidb.db1.default = true
resources.multidb.db3.adapter = "PDO_MYSQL"
resources.multidb.db3.dbname = "xxxxxx"
resources.multidb.db3.username = "xxxxxx"
resources.multidb.db3.password = "xxxxxx"
resources.multidb.db3.hostname = "xxxxx"
resources.multidb.db3.charset = "UTF8"
resources.multidb.db3.default = false
这是我的Bootstrap.php:
/**
* Add databases to the registry
*/
public function _initDbRegistry()
{
$this->bootstrap('multidb');
$multidb = $this->getPluginResource('multidb');
Zend_Registry::set('local', $multidb->getDb('db1'));
Zend_Registry::set('db2', $multidb->getDb('db2'));
Zend_Registry::set('db3', $multidb->getDb('db3'));
}
这是我的模特:
class ModuleName_Model_ModelName extends Zend_Db_Table_Abstract
{
protected $_name;
protected $_schema;
protected $_db; // changed from $_adapter in tutorial for Zend 1.11
public function init()
{
$this->_name = 'contacts';
$this->_schema = 'xxxxx';
$this->_db = Zend_Registry::get('db3');
}
}
这是我在控制器中调用的地方:
$model = new ModuleName_Model_ModelName();
$this->view->output= $model->fetchAll();
我通过phpmyadmin,mysql workbench连接,并通过复制和粘贴相同的用户名和密码使用普通的旧mysql_connect。毫无疑问,用户名和密码是正确的。任何人都知道我在Zend中做错了什么是抛出拒绝访问错误?
好的,谢谢 - 我尝试了你的建议,Midhun:
Zend_Debug::dump($model->getAdapter()->getConfig());
我确实得到了正确的输出。
还有其他想法吗?
答案 0 :(得分:1)
试试这个以进行调试并检查适配器是否完全符合您的预期......
$model = new ModuleName_Model_ModelName();
Zend_Debug::dump($model->getAdapter()->getConfig());