Jump to content

Recommended Posts

when i try and run multiple stored procedures, the second mysqli_query call fails, and i get the following error.

 

here is the error:

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

 

here is my code:

if($result = mysqli_query($link, "call spSelectProductData(1888);")){
$pa = mysqli_fetch_array($result);
print_r($pa);
}else{
echo mysqli_error($link);
}
if($result = mysqli_query($link, "select * from tblProducts")){
$pa = mysqli_fetch_array($result);
print_r($pa);
}else{
echo mysqli_error($link);
}

Link to comment
https://forums.phpfreaks.com/topic/74783-php-mysql-stored-procedures/
Share on other sites

well, i got the results i needed. it seems very awkward to do it this way, but it works. i have read that you have to use mysql_multi_query if you plan to make more than one stored procedure call in a script. is this true? anyway, here is how i got it to work.

 

$query  = "call spSelectProductData(1888);";
$query .= "call spSelectProductData(1889);";

/* execute multi query */
if (mysqli_multi_query($link, $query)) {

/* store first result set */
if ($result = mysqli_store_result($link)) {
	$pa = mysqli_fetch_array($result);
	print_r($pa);
	mysqli_free_result($result);
}

/* have to do it twice for some reason */
    mysqli_next_result($link);
mysqli_next_result($link);

/* store second result set */
if ($result = mysqli_store_result($link)) {
	$pa = mysqli_fetch_array($result);
	print_r($pa);
	mysqli_free_result($result);
}

}

/* close connection */
mysqli_close($link);

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.