tags:

views:

24

answers:

1

Hello,

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?

+1  A: 

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

"PHP 5 and MySQL 5 Stored Procedures Error"

armonge
The procedure has only 1 select.
Pentium10
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
http://dev.mysql.com/doc/refman/5.0/en/call.html
armonge