title: PHP Commands Out of Sync error
body: <p>I am using two prepared statements in PHP/MySQLi to retrieve data from a mysql database.  However, when I run the statements, I get the "Commands out of sync, you can't run the command now" error.</p>
  
  <p>Here is my code:</p>
  
  <pre><code>    $stmt = $mysqli-&gt;prepare("SELECT id, username, password, firstname, lastname, salt FROM members WHERE email = ? LIMIT 1";
      $stmt-&gt;bind_param('s', $loweredEmail);
      $stmt-&gt;execute();
      $stmt-&gt;store_result();
      $stmt-&gt;bind_result($user_id, $username, $db_password, $firstname, $lastname, $salt);
      $stmt-&gt;fetch();
  
      $stmt-&gt;free_result();
      $stmt-&gt;close();
  
      while($mysqli-&gt;more_results()){
          $mysqli-&gt;next_result();
      }
  
      $stmt1 = $mysqli-&gt;prepare("SELECT privileges FROM delegations WHERE id = ? LIMIT 1");
      //This is where the error is generated
      $stmt1-&gt;bind_param('s', $user_id);
      $stmt1-&gt;execute();
      $stmt1-&gt;store_result();
      $stmt1-&gt;bind_result($privileges);
      $stmt1-&gt;fetch();
  </code></pre>
  
  <p>What I've tried:</p>
  
  <ul>
  <li>Moving the prepared statements to two separate objects.</li>
  <li><p>Using the code:</p>
  
  <pre><code>while($mysqli-&gt;more_results()){
      $mysqli-&gt;next_result();
  }
  //To make sure that no stray result data is left in buffer between the first
  //and second statements
  </code></pre></li>
  <li>Using free_result() and mysqli_stmt->close()</li>
  </ul>
  
  <p>PS: The 'Out of Sync' error comes from the second statement's '$stmt1->error'</p>