-1

I am trying to do some calls, but the 2nd query fails with command 'Commands out of sync; you can't run this command now' error.

The code looks like this:

$sql="call listReport();";
$results = mysqli_query($link,$sql); 
$arr=array();
while($row=mysqli_fetch_array($results)) {
    array_push($arr,$row);
}
mysqli_free_result($results);

// then I have this

// but this fails, giving the above mentioned error
$stmt = @mysqli_prepare($link,"select ........") or die(mysqli_error($link));
@mysqli_stmt_bind_param($stmt, 's', $s);
@mysqli_stmt_execute($stmt);
@mysqli_stmt_bind_result($stmt, $s);
@mysqli_stmt_fetch($stmt);
@mysqli_stmt_close($stmt);

I actually used mysqli_free_result($results); but doesn't worked. What do I miss?

Dharman
  • 30,962
  • 25
  • 85
  • 135
Pentium10
  • 204,586
  • 122
  • 423
  • 502
  • Can you reproduce the error with this code? You're pushing `$row` to undefined `$arr`, and `$arrows` is not used. Do not suppress errors with `@`, any error messages can be helpful. (maybe a helpful link: [explanation of this error on the MySQL website](http://dev.mysql.com/doc/refman/5.1/en/commands-out-of-sync.html).) – Lekensteyn Sep 22 '10 at 13:59
  • On the first method of the second group fails, the die node prints the error. – Pentium10 Sep 22 '10 at 14:02

1 Answers1

1

The problem is that mysql stored procedures can return various result sets, so you should use mysqli_multiquery

Dharman
  • 30,962
  • 25
  • 85
  • 135
armonge
  • 3,108
  • 20
  • 36
  • The procedure has only 1 select. – Pentium10 Sep 22 '10 at 14:15
  • It's not about having just one select in your procedure, if you read the MySQL documentation you will see that "To write C programs that use the CALL SQL statement to execute stored procedures that produce result sets, the CLIENT_MULTI_RESULTS flag must be enabled." – armonge Sep 22 '10 at 14:30