Jump to content

php mysql stored procedures


fooDigi

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);

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.