title: mysql stored procedure error Commands out of sync; you can't run this command now
body: <p>I have a stored procedure which I call from PHP which works fine on my dev version which is running Maria DB. I transferred to production which is running mysql (5.5.53) a 'Commands out of sync; you can't run this command now' error. I have tried suggestions to make sure the connection is closed after each query. I have also tried $stmt->store_result(); &amp;  $stmt->free_result();. If I try $stmt-next_result(); I do not get this out of sync error, but my script exists the loop and I do not get any other results.</p>
  
  <p>Stored Procedure:</p>
  
  <pre><code>CREATE DEFINER=`root`@`localhost` PROCEDURE `test3`(IN `Input_Value` INT, OUT `Out_val` VARCHAR(150))
  BEGIN
      SET @sql = 'SELECT sample_name FROM sample';
      PREPARE stmt FROM @sql;
      EXECUTE stmt;
  END
  </code></pre>
  
  <p>PHP: 
      `
  
  <pre><code>foreach($locations as $location_name){
      echo $location_name.'&lt;br&gt;';
      $sp_query = "CALL test3(?,@Out_val)";
      $stmt = $dbc-&gt;prepare($sp_query);
      if(!$stmt){
          echo mysqli_error($dbc);
      }
      $stmt-&gt;bind_param('i',$view);
  
      if ($stmt-&gt;execute()){
          $params = array();
          $meta = $stmt-&gt;result_metadata();
          print_r($meta); 
  
          while ($field = $meta-&gt;fetch_field()){
              $params[] = &amp;$row[$field-&gt;name]; 
          }
          print_r($params); 
          call_user_func_array(array($stmt, 'bind_result'), $params); 
          $header_ct = 0; 
  
          $labels = '';
          while ($stmt-&gt;fetch()) {
              foreach($row as $key =&gt; $value){
                  $key = htmlspecialchars($key);
                  //echo "Key:".$key."&lt;br&gt;";
                  //echo "Value:".$value."&lt;br&gt;";
              }
          }
      }else{
          echo mysqli_error($dbc);
          echo "not working";
      }
      $stmt-&gt;store_result();
      //$stmt-&gt;free_result();
      $stmt-&gt;close();                 
  }           
  
  ?&gt;`
  </code></pre>