Page 1 of 1

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

Posted: Wed Jun 13, 2007 10:24 am
by olog-hai
Everah | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


Hi,

I'm stuck with this error. give me hint.

Code: Select all

$objSession &= new Session(); #my class that extend mysqli
...
$query = "Call Nouvelle_Get(".$_REQUEST['newId'].");";
	
$objSession->executeSQL( $query );
$result = $objSession->store_result();
$result->close();
$objSession->executeSQL( $query );    # ERROR ON THIS LINE
$result = $objSession->store_result();
...
Why i get this error even I flushed the result ?

here is the code of my function in my class that extends mysqli

Code: Select all

public function executeSQL( $sql ) {
  $this->multi_query( $sql ) or $this->dienice( $this->errno, $this->error." <br><br>SQL SOURCE: ".$sql );
}
The first call works not the second.

thanks for your time :roll:


Everah | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]

Posted: Wed Jun 13, 2007 11:04 am
by superdezign
Any chances that "$result->close();" has anything to do with it?

Posted: Wed Jun 13, 2007 11:15 am
by olog-hai
No isn't due to the $result->close(); it's due to the second call consecutive.

I read this on the php.net

If you use MYSQLI_USE_RESULT all subsequent calls will return error Commands out of sync unless you call mysqli_free_result()

http://ca.php.net/manual/en/function.mysqli-query.php

But I don't use Mysqli_quey and I dont' use MYSQLI_USE_RESULT .

I'm trying to find why I can't use mysqli_quey_multi 2 times.

Anyone else got this error ?

can someone try it ? try to use mysqli_query_multi 2 times without work or use the result between the call.

thanks.

Posted: Wed Jun 13, 2007 12:46 pm
by RobertGonzalez
Edit | Didn't like my first answer....

Try running this on your server using the query you entered above. If this works, then there is a problem with your class code that needs to be resolved.

Code: Select all

<html>
<head><title>Stored Procedure Tester - MySQL</title></head>

<body>
<?php
$sql = '';
$show_results = false;

if (isset($_POST['form_submitted']))
{
    // The form was submitted
    $sql = $_POST['query'];
    
    echo '<p>The query you entered entered was <strong>' . $sql . '</strong>.</p>';

    // Make sure you add your information here
    $mysql = new mysqli('localhost', 'database-username', 'database-password', 'database-name');
    
    if (mysqli_connect_errno())
    {
        die(printf('MySQL Server connection failed: %s', mysqli_connect_error()));
    }
    
    // Check our query results
    if ($mysql->multi_query($sql)) 
    {
        $show_results = true;
        $rs = array();
        
        do {
            // Lets work with the first result set
            if ($result = $mysql->use_result()) 
            {
                // Loop the first result set, reading it into an array
                while ($row = $result->fetch_array(MYSQLI_ASSOC)) 
                {
                    $rs[] = $row;
                }
                
                // Close the result set
                $result->close();
            }
        } while ($mysql->next_result());
    }
    else
    {
        echo '<p>There were problems with your query [' . $sql . ']:<br /><strong>Error Code ' . $mysql->errno . ' :: Error Message ' . $mysql->error . '</strong></p>';
    }
    
    $mysql->close();
}

echo '<form id="proc_tester" action="' . basename($_SERVER['SCRIPT_FILENAME']) . '" method="post">
    <p>Enter your procedure:</p>
    <p><input type="text" name="query" size="175" maxlength="255" value="' . $sql . '" /></p>
    <p><input type="hidden" name="form_submitted" value="true" /><input type="submit" name="submit" value="Submit query" /></p>
</form>';

if ($show_results) {
    echo '<pre>';
    print_r($rs);
    echo '</pre>';
}
?>
</body>
</html>

Posted: Wed Jun 13, 2007 12:55 pm
by olog-hai
Yes my stored procedure return 2 resultset.

I tried mysqli_query with a strored procedure that return 1 resultset and i got the same error.

first call works and the second failed.

is someone can test it on his own to validate that i'm not stupid ? :lol:

thanks.

Posted: Wed Jun 13, 2007 12:56 pm
by RobertGonzalez
See my edit to my last post. I think you have to use mysqli_use_result().

/ Sorry, you replied before I could edit it. :oops:

Posted: Wed Jun 13, 2007 1:03 pm
by Benjamin
You need to cycle through all the results and free them before you can run another query. Read through the mysqli functions in the manual.

Code: Select all

while (mysqli_next_result($db_link)) {}

Posted: Wed Jun 13, 2007 2:53 pm
by olog-hai
Great !!

it works !! We have to cycle through all the results and free them before you can run another query.

Thanks for all