my authentication fails and when i try to getDbSelect() i get nothing ... what did i do wrong?
class AuthController extends Zend_Controller_Action { protected $auth; public function init() { $db = $this->getInvokeArg("bootstrap")->getResource("db"); $this->auth = new Zend_Auth_Adapter_DbTable($db, 'users', 'username', 'password', 'md5(?)'); } public function loginAction() { if (isset($_POST["username"])) { $result = $this->auth ->setIdentity($this->getRequest()->getParam('username')) ->setCredential($this->getRequest()->getParam('password')); echo " > " . $this->auth->getDbSelect();die(); $result = $this->auth ->setIdentity($this->getRequest()->getParam('username')) ->setCredential($this->getRequest()->getParam('password')) ->authenticate(); if ($result->isValid()) { $this->_redirect("postLogin"); } } }
Update 1:
i also tried without MVC and with MySQL which i am more familiar with:
// setup auto loading require_once 'Zend/Loader/Autoloader.php'; Zend_Loader_Autoloader::getInstance(); // setup db connection $db = new Zend_Db_Adapter_Pdo_Mysql(array( 'host' => '127.0.0.1', 'username' => 'root', 'password' => '', 'dbname' => 'learnZendAuth' )); // create authentication adapter $auth = new Zend_Auth_Adapter_DbTable($db, 'users', 'username', 'password', 'md5(?)'); // do login if request is posted if (isset($_POST) && !empty($_POST)) { // do authencation $result = $auth->setIdentity($_POST['username']) ->setCredential($_POST['password']) ->authenticate(); // check authentication valid if ($result->isValid()) { // login success echo "successfully logged in as: " . $result->getIdentity(); } else { // login fail echo ""; print_r($result->getMessages()); echo ""; } } else { // request not posted // see if already logged in if (Zend_Auth::getInstance()->hasIdentity()) { echo "already logged in as: " . Zend_Auth::getInstance()->getIdentity(); } }
i get
Fatal error: Uncaught exception 'Zend_Auth_Adapter_Exception' with message 'The supplied parameters to Zend_Auth_Adapter_DbTable failed to produce a valid sql statement, please check table and column names for validity.' in C:\Program Files (x86)\Zend\ZendServer\share\ZendFramework\library\Zend\Auth\Adapter\DbTable.php:414 Stack trace: #0 C:\Program Files (x86)\Zend\ZendServer\share\ZendFramework\library\Zend\Auth\Adapter\DbTable.php(306): Zend_Auth_Adapter_DbTable->_authenticateQuerySelect(Object(Zend_Db_Select))
1 C:\Program Files (x86)\Zend\Apache2\htdocs\learnZf\index.php(23):
Zend_Auth_Adapter_DbTable->authenticate()
2 {main} thrown in C:\Program Files (x86)\Zend\ZendServer\share\ZendFramework\library\Zend\Auth\Adapter\DbTable.php
on line 414