开发者

Commands out of sync when using mysqli and prepared statements [duplicate]

开发者 https://www.devze.com 2023-01-17 16:28 出处:网络
This question already has answers here: Commands out of sync; you can't run this command now (23 answers)
This question already has answers here: Commands out of sync; you can't run this command now (23 answers) Closed 2 years ago.

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 t开发者_Go百科he 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?


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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号