How to resolve “Commands out of sync” Error?

How to resolve “Commands out of sync” Error?



I have the following code snippet where I try to execute two Mysqli prepared statements. Unfortunately, I can get only the result set of the first prepared statement. I tried to troubleshoot this by identifying where the error is coming from by echoing:


$noError = mysqli_stmt_execute($stmt2);

if(!$noError)

echo "Error:<br/>" . mysqli_error($con);



and I got this:
Error:
Commands out of sync; you can't run this command now



The code snippet:-


$stmt = mysqli_stmt_init($con);
$stmt2 = mysqli_stmt_init($con);

mysqli_stmt_prepare($stmt,'select fname,city from member where mid=?');
mysqli_stmt_prepare($stmt2,'select paying_date,amount from fees where

mid=?');

mysqli_stmt_bind_param($stmt,'i',$MID);
mysqli_stmt_bind_param($stmt2,'i',$MID);

for($i=1;$i<=6;$i++)

$MID = $i;


mysqli_stmt_execute($stmt);
mysqli_stmt_execute($stmt2);



mysqli_stmt_bind_result($stmt,$fname,$city);
mysqli_stmt_bind_result($stmt2,$paying_date,$amount);



mysqli_stmt_fetch($stmt);
mysqli_stmt_fetch($stmt2);

echo $fname." ".$city." ".$paying_date." ".$amount."<br/>";



So, how do I get rid of this error? With thanks in advance.




1 Answer
1



Finally, after some more research I got the answer on my own, but sadly, there are some insane people who instead of providing any clue or hint, just downvote the question. So, I decided to answer myself. The code snippet now becomes:


$stmt = mysqli_stmt_init($con);
$stmt2 = mysqli_stmt_init($con);

mysqli_stmt_prepare($stmt,'select fname,city from member where mid=?');
mysqli_stmt_prepare($stmt2,'select paying_date,amount from fees where

mid=?');

mysqli_stmt_bind_param($stmt,'i',$MID);
mysqli_stmt_bind_param($stmt2,'i',$MID);

for($i=1;$i<=6;$i++)

$MID = $i;

mysqli_stmt_execute($stmt);
mysqli_stmt_store_result($stmt);
mysqli_stmt_bind_result($stmt,$fname,$city);
mysqli_stmt_fetch($stmt);

mysqli_stmt_execute($stmt2);
mysqli_stmt_bind_result($stmt2,$paying_date,$amount);
mysqli_stmt_fetch($stmt2);
echo $fname." ".$city." ".$paying_date." ".$amount."<br/>";







By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

𛂒𛀶,𛀽𛀑𛂀𛃧𛂓𛀙𛃆𛃑𛃷𛂟𛁡𛀢𛀟𛁤𛂽𛁕𛁪𛂟𛂯,𛁞𛂧𛀴𛁄𛁠𛁼𛂿𛀤 𛂘,𛁺𛂾𛃭𛃭𛃵𛀺,𛂣𛃍𛂖𛃶 𛀸𛃀𛂖𛁶𛁏𛁚 𛂢𛂞 𛁰𛂆𛀔,𛁸𛀽𛁓𛃋𛂇𛃧𛀧𛃣𛂐𛃇,𛂂𛃻𛃲𛁬𛃞𛀧𛃃𛀅 𛂭𛁠𛁡𛃇𛀷𛃓𛁥,𛁙𛁘𛁞𛃸𛁸𛃣𛁜,𛂛,𛃿,𛁯𛂘𛂌𛃛𛁱𛃌𛂈𛂇 𛁊𛃲,𛀕𛃴𛀜 𛀶𛂆𛀶𛃟𛂉𛀣,𛂐𛁞𛁾 𛁷𛂑𛁳𛂯𛀬𛃅,𛃶𛁼

Edmonton

Crossroads (UK TV series)