2013-03-21 69 views
0

我试图在zend框架中进行登录,但是PDO给了我一个错误。 我有以下功能:'where子句'中的未知列'Array'ZF1

public function isCorrectLogin (Application_Model_User $user){ 

    $row = $this->_db_table->fetchRow(
       $this->_db_table 
        ->select() 
        ->where(array ('email = ?' => $user->email, 
            'password = ?' => sha1(SALT.$user->password))) 
          ); 

    if(empty($row)){ 
     return false; 
    } 
    return true;     
} 

在我的控制,我使用这个功能:

$oUserActions = new Application_Model_UserMapper(); 

      $user = new Application_Model_User(); 
      $user->email = $_REQUEST['email'];   
      $user->password = $_REQUEST['password']; 

      if($oUserActions->isCorrectLogin($user)){     
       echo 'validated';     
      } 

即时得到这个错误:

Message: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'Array' in 'where clause' 

Stack trace: 

#0 C:\webserver\htdocs\photo\library\Zend\Db\Statement.php(303): Zend_Db_Statement_Pdo->_execute(Array) 
#1 C:\webserver\htdocs\photo\library\Zend\Db\Adapter\Abstract.php(480): Zend_Db_Statement->execute(Array) 
#2 C:\webserver\htdocs\photo\library\Zend\Db\Adapter\Pdo\Abstract.php(238): Zend_Db_Adapter_Abstract->query(Object(Zend_Db_Table_Select), Array) 
#3 C:\webserver\htdocs\photo\library\Zend\Db\Table\Abstract.php(1575): Zend_Db_Adapter_Pdo_Abstract->query(Object(Zend_Db_Table_Select)) 
#4 C:\webserver\htdocs\photo\library\Zend\Db\Table\Abstract.php(1437): Zend_Db_Table_Abstract->_fetch(Object(Zend_Db_Table_Select)) 
#5 C:\webserver\htdocs\photo\application\models\UserMapper.php(49): Zend_Db_Table_Abstract->fetchRow(Object(Zend_Db_Table_Select)) 
#6 C:\webserver\htdocs\photo\application\controllers\LoginController.php(31): Application_Model_UserMapper->getUserLogin(Object(Application_Model_User)) 

有没有人有一个想法,我在做什么错误?

+0

你为什么要用数组? – 2013-03-21 19:17:50

+0

http://net.tutsplus.com/tutorials/php/zend-framework-from-scratch-models-and-integrating-doctrine-orm/因为我按照这个教程了一下,他们也在这里做 – 2013-03-21 19:23:57

+0

你'不要使用它与$ this - > _ db_table-> update($ data,array('id =?'=> $ user_object-> id));他们有两个参数,第一个是包含输入字段的关联数组 – 2013-03-21 19:31:33

回答

3

试试这个。你为什么使用数组。

$select->where(
     $db->quoteInto('email = ?', => $user->email) . ' AND ' . $db->quoteInto('password = ?', sha1(SALT.$user->password)) 
    ); 
    // $db is your instance of Zend_Db_Adapter_* 
    // You can get it from a Zend_Db_Table_Abstract 
    //subclass by calling its getAdapter() method