views:

698

answers:

1

So followed all the basic tutorials. Am using Zend 1.8 but i keep getting this exception when using Zend_Auth_DB. Any ideas, there is only one row in the table.

Exception information:

Message: The supplied parameters to Zend_Auth_Adapter_DbTable failed to produce a valid sql statement, please check table and column names for validity.

Stack trace:

#0 C:\projects\BHAA_ZEND\library\Zend\Auth\Adapter\DbTable.php(306): Zend_Auth_Adapter_DbTable->_authenticateQuerySelect(Object(Zend_Db_Select))
#1 C:\projects\BHAA_ZEND\library\Zend\Auth.php(117): Zend_Auth_Adapter_DbTable->authenticate()
#2 C:\projects\BHAA_ZEND\application\controllers\LoginController.php(79): Zend_Auth->authenticate(Object(Zend_Auth_Adapter_DbTable))
#3 C:\projects\BHAA_ZEND\application\controllers\LoginController.php(38): LoginController->getAuthAdapter(Array)
#4 C:\projects\BHAA_ZEND\library\Zend\Controller\Action.php(512): LoginController->processAction()
#5 C:\projects\BHAA_ZEND\library\Zend\Controller\Dispatcher\Standard.php(288): Zend_Controller_Action->dispatch('processAction')
#6 C:\projects\BHAA_ZEND\library\Zend\Controller\Front.php(945): Zend_Controller_Dispatcher_Standard->dispatch(Object(Zend_Controller_Request_Http), Object(Zend_Controller_Response_Http))
#7 C:\projects\BHAA_ZEND\library\Zend\Application\Bootstrap\Bootstrap.php(77): Zend_Controller_Front->dispatch()
#8 C:\projects\BHAA_ZEND\library\Zend\Application.php(328): Zend_Application_Bootstrap_Bootstrap->run()
#9 C:\projects\BHAA_ZEND\public\index.php(33): Zend_Application->run()
#10 {main}

Here's the offending code.

public function getAuthAdapter(array $params)
{
    $dbAdapter = Zend_Db_Table::getDefaultAdapter();
    $authAdapter = new Zend_Auth_Adapter_DbTable($dbAdapter);

    $authAdapter->setTableName('login')
                ->setIdentityColumn('username')
                ->setCredentialColumn('password');
                //->setCredentialTreatment('MD5(?)');
    // pass to the adapter the submitted username and password
    $authAdapter->setIdentity($username)->setCredential($password);

    $auth = Zend_Auth::getInstance();
    $result = $auth->authenticate($authAdapter);
    if ($result->isValid()) {
                 // success : store database row to auth's storage system
                 // (not the password though!)
                 $data = $authAdapter->getResultRowObject(null, 'password');
                 $auth->getStorage()->write($data);
                 //$this->_redirect('/');
                 return $this->_helper->redirector('index','index');
             } else {
                 // failure: clear database row from session
                 $this->view->message = 'Login failed.';
                 return $this->render('index');
             }
    return $result;
}

Have you read the documentation for Zend_Auth_Adapter_DbTable? - Yes, but i'm not sure if it cleared or muddied my understanding.

Do you have a valid connection to the database? - Yup, have a working CRUD app with the same DB config.

What is the structure of your users table? -

Did you specify the identity and credential columns correctly to the constructor of Zend_Auth_Adapter_DbTable? - See code above, i believe so.

Did you also specify the username/password you're trying to authenticate? - Yup, have a Zend form submitting these variables.

What is the SQL query that is causing the error? I think this is it.

SELECT `isp_partners_view`.*, (CASE WHEN `password` = '*****' THEN 1 ELSE 0 END) AS `zend_auth_credential_match` FROM `isp_partners_view` WHERE (`username` = '*****')
+2  A: 

You have given the error, but there are number of other questions I'd ask to try to troubleshoot this:

  • Have you read the documentation for Zend_Auth_Adapter_DbTable?

  • Do you have a valid connection to the database?

  • What is the structure of your users table?

  • Did you specify the identity and credential columns correctly to the constructor of Zend_Auth_Adapter_DbTable?

  • Did you also specify the username/password you're trying to authenticate?

  • What is the SQL query that is causing the error? You can view the query this way:

    $select = $authAdapter->getDbSelect();
    print $select . "\n";
    
Bill Karwin