1

I want to execute two queries in zend 2 :

This is the content of my model file:

 $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();

For some reason if i remove one random query, the another one will be executed. I know it is weird but i believe there is a rational answer to it. The result of the try catch part is:

enter image description here

I did not write it wrong the query. AS you can see I tried a simple select query and i got the same result. Actually I have no idea what is wrong this. Please help with this, I'm looking up for an answer on the internet during the last 5-6 days and I found nothing. If you want me to provide any more information, please ask. THX

Jozsef Naghi
  • 1,085
  • 3
  • 14
  • 32

1 Answers1

0

As this answer suggests, this is an issue with the mysqli driver using unbuffered queries by default.

To fix this, you have to buffer the result of the first query before running the next one. With ZF2, the Result interface has a buffer() method to achieve this :

$results = $select->execute();
$results->buffer();
Community
  • 1
  • 1
moustachio
  • 41
  • 1
  • 4