title: "Cannot execute queries while other unbuffered queries are active" error in loop
body: <p>I'm sorry for asking this question. I've read alot just like it, but never found a solution that I successfully could implement. All the tips and tricks that I've found has been  to no use for me.</p>
  
  <p>I have a large associative array with data that I want to insert into a mysql database using a stored procedure with PDO.</p>
  
  <pre><code>$data_arr = {a lot of data with keys: Name, Nbr, Val} //This is really 41 columns
  $inputs = array('Name','Nbr','Val');
  $query = 'CALL add_edit_standard(:Name,:Nbr,:Val)';
  $stmt = $db-&gt;prepare($query);
  foreach($inputs AS $Akey =&gt; $Aval){
      $values[$Aval]=0;
      $stmt-&gt;bindParam(':'.$Aval,$values[$Aval]);
  }
  foreach($data_arr AS $key =&gt; $val){
      $values = $val;
      $stmt-&gt;execute();
      $res = $stmt-&gt;fetchAll();
  }
  </code></pre>
  
  <p>This works perfectly fine for the first row in $data_arr, but the second and the rest throws an error:</p>
  
  <blockquote>
    <p>Warning: PDOStatement::execute(): SQLSTATE[HY000]: General error: 2014 Cannot execute queries while other unbuffered queries are active. Consider using PDOStatement::fetchAll(). Alternatively, if your code is only ever going to run against mysql, you may enable query buffering by setting the PDO::MYSQL_ATTR_USE_BUFFERED_QUERY attribute.</p>
  </blockquote>
  
  <p>I've tried with the fetchAll(), as well as the connection attribute with no luck.
  I've also tried to make a new statement for each call:</p>
  
  <pre><code>foreach($data_arr AS $key =&gt; $val)
  {
      $values = $val;
      $stmt = $db-&gt;prepare($query);
      foreach($inputs AS $Akey =&gt; $Aval)
      {
          $stmt-&gt;bindValue(':'.$Aval,$values[$Aval]);
      }
      $stmt-&gt;execute();
      $res = $stmt-&gt;fetchAll();
      $stmt-&gt;closeCursor();
  }
  </code></pre>
  
  <p>Again, this works perfectly for the first row, but then throws the following error:</p>
  
  <blockquote>
    <p>Warning: Packets out of order. Expected 1 received 57. Packet size=7</p>
  </blockquote>
  
  <p>I have tried everything I've come up with. Please help me to find a way to make it work.</p>