0

Below is the code that i am having trouble with:

$stmt->store_result();
if($stmt->num_rows<1) return false;
$res2=$stmt->get_result();
if($GLOBAL_DB->error) die($GLOBAL_DB->error);
while($res=$res2->fetch_array(MYSQLI_ASSOC)) $result[]=$res['Field'];

I get the following error when i run the code: Commands out of sync; you can't run this command now. Everything before this code works 100% because it has been tested. The thing is, this code worked before, but then i wanted to check on the num_rows as well as fetching.
The following code works fine:

$res2=$stmt->get_result();
if($GLOBAL_DB->error) die($GLOBAL_DB->error);
while($res=$res2->fetch_array(MYSQLI_ASSOC)) $result[]=$res['Field'];

This is the error i'm getting

Commands out of sync; you can't run this command now

131
  • 1,363
  • 1
  • 12
  • 32
  • `return false;` Is the first code in a function/method???? If so show it as such – RiggsFolly Dec 05 '16 at 17:48
  • 2
    There's no need to use `$stmt->store_result();`. After `$res2=$stmt->get_result();`, you can directly use `$res2->num_rows` to get the number of rows. – Rajdeep Paul Dec 05 '16 at 17:48
  • Removed `store_result();` and it worked. I swear i tried to do that before and it kept showing an error. Anyways, THANKS! Could you throw an answer? – 131 Dec 05 '16 at 17:52
  • Wait, nvm. it didn't actually work – 131 Dec 05 '16 at 17:56

0 Answers0