2013-01-21 41 views
0

MySQL的兩種程序和會話分貝我有一個這樣的控制器:使用代碼點火器的原因`2014`錯誤

$r_result = $this->storedprocedure->user_email_exist($in_email); 

if($r_result->num_rows() == 1) 
{ 
    foreach ($r_result->result() as $row) 
    { 
     $salt = $row->salt; 
     $hash = $row->hash_password; 
     if(strcasecmp(Application_Helper::hash_password($aData['password'], $salt), 
      $hash)==0) 
     { 
      //Login success 
      echo('login success'); 

      $newdata = array('user_id' => $row->id); 
      $this->session->set_userdata($newdata); 
     } 
    } 
} 

在StoredProcedure的模型,是這樣的:

public function user_email_exist($aEmail) 
{ 
    $r_result = $this->db->query("CALL user_email_exist('".$aEmail."')"); 

    return $r_result; 
} 

我測試它,它可以登錄成功,但打印錯誤:

A Database Error Occurred

Error Number: 2014

Commands out of sync; you can't run this command now

UPDATE ci_sessions SET last_activity = 1358764263, user_data = 'a:2:{s:9:\"user_data\";s:0:\"\";s:7:\"user_id\";s:2:\"35\";}' WHERE session_id = '05e340b2aa6bd9b21261ed0d20354b3c'

Filename: libraries/Session.php

Line Number: 289

的問題是,我必須使用MySQL procedure來實現模型層,但似乎在ci_session之間有一些衝突。任何推薦解決方案的問題?謝謝。

回答

0

此錯誤是由於mySQL存儲過程返回多個結果 而引起的,即使它們中只有一個select語句。解決方法是簡單地調用$ r_result-> next_result()來釋放預期的外部結果集。

我從這個link得到了主意。

請更換像下面的控制器代碼:

$r_result = $this->storedprocedure->user_email_exist($in_email); 

if($r_result->num_rows() == 1) 
{ 
    $row = $r_result->row_array(); 
    $r_result->next_result(); // Dump the extra resultset. 
    $r_result->free_result(); // Does what it says. 

    $salt = $row->salt; 
    $hash = $row->hash_password; 
    if(
     strcasecmp(Application_Helper::hash_password($aData['password'], $salt),$hash)==0 
    ) { 
     //Login success 
     echo('login success'); 

     $newdata = array('user_id' => $row->id); 
     $this->session->set_userdata($newdata); 
    } 

} 
+0

嗨@Ted皇請讓我知道,如果這有助於。 – OMG

+0

嗨,它不起作用。 'PHP致命錯誤:調用未定義的方法CI_DB_mysqli_result :: next_result()。 '相反,我這樣做:'$ this-> db-> close();' 登錄成功後,它在沒有錯誤的情況下工作。我不知道這是一種正確的做法。 – DNB5brims