2015-01-11 22 views
1

執行簡單的查詢問題,我想在Zend的2執行兩個查詢:在Zend的2

這是我的模型文件的內容:

$email = $getData['login_email']; 
     $password = $getData['login_password']; 
     $select = $this->adapter->query ("select count(*) as counter from users where email = '$email' and password = '".md5($password)."'"); 
     $results = $select->execute(); 
     if ($results->current()['counter'] == 1){ 
      // $update_user = $this->adapter->query("UPDATE users SET session_id = '".$session_id."' WHERE email = '".$email."'"); 
      try { 
      $update_user = $this->adapter->query("select * from users"); 
      } catch (\Exception $e) { 
       \Zend\Debug\Debug::dump($e->__toString()); exit; 
      } 
      $update_session = $update_user->execute(); 

出於某種原因,如果我刪除一個隨機查詢,另一個將被執行。我知道這很奇怪,但我相信這有一個合理的答案。在嘗試捕捉部分的結果是:

enter image description here

沒寫是錯誤的查詢。正如你所看到的,我嘗試了一個簡單的選擇查詢,並得到了相同的結果。其實我不知道這是什麼問題。請幫忙,我在過去的5-6天內在網上尋找答案,我什麼也沒找到。如果您希望我提供更多信息,請詢問。 THX

+0

任何人,一些ideea? –

回答

0

由於this answer暗示,這是mysqli驅動程序默認使用未緩衝查詢時的問題。

要解決此問題,必須在運行下一個查詢之前緩衝第一個查詢的結果。使用ZF2,Result接口有一個buffer()方法來實現這一點:

​​
+0

現在我得到這個:不能緩衝已經開始迭代的結果集。任何想法爲什麼? –

+0

thx男人你救了我的一天!!!! –