在 Zend Framework 中 Zend_Db_Table::getDefaultAdapter() 返回 Null
在互联网上搜索后,没有找到正确的答案,我问你:
我想实现一个 getAuthAdapter(array $form)
private function getAuthAdapter(array $form) {
$authAdapter = new Zend_Auth_Adapter_DbTable(
Zend_Db_Table::getDefaultAdapter(),
'user',
'email',
'password',
'MD5(?) AND hidden = "FALSE"');
$authAdapter->setIdentity($form['email'])
->setCredential($form['password']);
return $authAdapter;
}
为了建立数据库连接,我将以下几行添加到我的 >application.ini
resources.db.adapter = "PDO_MYSQL"
resources.db.params.host = "localhost"
resources.db.params.username = web5
resources.db.params.password = ACv8vSdn
resources.db.params.dbname = usr_web5_1
resourses.db.isDefaultTableAdapter = true
但是在尝试该脚本后我遇到以下错误:
Application error
Exception information:
Message: No database adapter present
Stack trace:
0 /usr/share/php/libzend-framework-php/Zend/Auth/Adapter/DbTable.php(140): Zend_Auth_Adapter_DbTable->_setDbAdapter(NULL)
1 /var/www/web5/html/application/controllers/LoginController.php(49): Zend_Auth_Adapter_DbTable->__construct(NULL, 'user', 'email', 'password', 'MD5(?) AND hidd...')
2 /var/www/web5/html/application/controllers/LoginController.php(23): LoginController->getAuthAdapter(Array)
3 /usr/share/php/libzend-framework-php/Zend/Controller/Action.php(513): LoginController->indexAction()
4 /usr/share/php/libzend-framework-php/Zend/Controller/Dispatcher/Standard.php(295): Zend_Controller_Action->dispatch('indexAction')
5 /usr/share/php/libzend-framework-php/Zend/Controller/Front.php(954): Zend_Controller_Dispatcher_Standard->dispatch(Object(Zend_Controller_Request_Http), Object(Zend_Controller_Response_Http))
6 /usr/share/php/libzend-framework-php/Zend/Application/Bootstrap/Bootstrap.php(97): Zend_Controller_Front->dispatch()
7 /usr/share/php/libzend-framework-php/Zend/Application.php(366): Zend_Application_Bootstrap_Bootstrap->run()
8 /var/www/web5/html/public/index.php(26): Zend_Application->run()
9 {main}
Request Parameters:
array (
'controller' => 'login',
'action' => 'index',
'module' => 'default',
'email' => '[email protected]',
'password' => 'test',
'login' => 'Login',
)
after serching up and down the internets, finding no proper answer, I am asking you:
I want to implement a getAuthAdapter(array $form)
private function getAuthAdapter(array $form) {
$authAdapter = new Zend_Auth_Adapter_DbTable(
Zend_Db_Table::getDefaultAdapter(),
'user',
'email',
'password',
'MD5(?) AND hidden = "FALSE"');
$authAdapter->setIdentity($form['email'])
->setCredential($form['password']);
return $authAdapter;
}
To establish a database connection, I added following lines to my application.ini
resources.db.adapter = "PDO_MYSQL"
resources.db.params.host = "localhost"
resources.db.params.username = web5
resources.db.params.password = ACv8vSdn
resources.db.params.dbname = usr_web5_1
resourses.db.isDefaultTableAdapter = true
But after trying the script I experience following error:
Application error
Exception information:
Message: No database adapter present
Stack trace:
0 /usr/share/php/libzend-framework-php/Zend/Auth/Adapter/DbTable.php(140): Zend_Auth_Adapter_DbTable->_setDbAdapter(NULL)
1 /var/www/web5/html/application/controllers/LoginController.php(49): Zend_Auth_Adapter_DbTable->__construct(NULL, 'user', 'email', 'password', 'MD5(?) AND hidd...')
2 /var/www/web5/html/application/controllers/LoginController.php(23): LoginController->getAuthAdapter(Array)
3 /usr/share/php/libzend-framework-php/Zend/Controller/Action.php(513): LoginController->indexAction()
4 /usr/share/php/libzend-framework-php/Zend/Controller/Dispatcher/Standard.php(295): Zend_Controller_Action->dispatch('indexAction')
5 /usr/share/php/libzend-framework-php/Zend/Controller/Front.php(954): Zend_Controller_Dispatcher_Standard->dispatch(Object(Zend_Controller_Request_Http), Object(Zend_Controller_Response_Http))
6 /usr/share/php/libzend-framework-php/Zend/Application/Bootstrap/Bootstrap.php(97): Zend_Controller_Front->dispatch()
7 /usr/share/php/libzend-framework-php/Zend/Application.php(366): Zend_Application_Bootstrap_Bootstrap->run()
8 /var/www/web5/html/public/index.php(26): Zend_Application->run()
9 {main}
Request Parameters:
array (
'controller' => 'login',
'action' => 'index',
'module' => 'default',
'email' => '[email protected]',
'password' => 'test',
'login' => 'Login',
)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可能想检查引导程序并调试加载数据库的代码。
You might want to check you bootstrapper and debug your code which loads the db.