Jump to content

Problem calling one stored procedure after another


pandyboy

Recommended Posts

I am tearing my hair out over this:

 

<?php
$mysqli = new mysqli("localhost", "username", "password", "database");

$query1="CALL procedure1 (1)";
$insert=$mysqli->query($query1);
$row = $insert->fetch_array();
print_r($row);
$insert->free_result();

$query2="CALL procedure2 (1,2,3)";
if (!$mysqli->query($query2)) {
printf("Error: %s\n", $mysqli->error ."<br />");
}
$mysqli->close();
?>

 

It refuses to run the second SP giving me a "Commands out of sync; you can't run this command now" error, despite me using the "$insert->free_result();" on the first one.

 

If I do the same as above but use procedural instead of OO style, it works fine. I don't wish to use procedural style, as I am using this within a class.

 

I can't use the mysqli_multi_query as the second procedure relies on the information returned by the first.

Link to comment
Share on other sites

why are you using $insert->fetch_array() I do not see you calling an object called $insert. Looking at what you have for code shouldn't it be $mysqli->fetch_array() and $mysqli->free_result()

 

Ray

Link to comment
Share on other sites

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.