ID:               42548
 User updated by:  garethjo at usc dot edu
 Reported By:      garethjo at usc dot edu
 Status:           Assigned
 Bug Type:         MySQLi related
 Operating System: Windows XP, Windows 2003
 PHP Version:      5.2.4
 Assigned To:      georg
 New Comment:

This is the example of the code from my initial bug report reworked to
use the multi_query.  It uses the same database setup script as the
original script in the first bug report and produces the same error:


//------------ BUG TEST START  --------------------------
$mysqli = mysqli_init();        
$mysqli->real_connect('localhost', 'root', 'root_pass', 'test');
if (mysqli_connect_errno())
{
    printf("Connect failed: %s\n", mysqli_connect_error());
    exit();
}

if($mysqli->multi_query ("CALL spGetProducts();"))
{
        do
        {
                        if($objResult = $mysqli->store_result())
                        {
                                while($row = $objResult->fetch_assoc())
                                {
                                        print $row["strProductName"]."
".$row["douProductPrice"]."<br>\r\n";
                                }
                                $objResult->close();
                                if($mysqli->more_results())
                                {
                                        print "------------------------<BR>";
                                }
        
                        }
                        else
                        {
                                print "no results found";
                        }
        }while ( $mysqli->next_result());
        
}
else
{       
        print $mysqli->error;
}
$mysqli->close();
?>


Previous Comments:
------------------------------------------------------------------------

[2007-09-12 08:55:24] uwendel at mysql dot com

Your code snippets does not show proper usage of mysqli_multi_query().


Stored Procedures that return n result sets will return n + 1 result
sets. In your case, it's two result sets to fetch and eat up before you
can reuse the line. The error message from the server is exactly about
that. Proper usage of mysqli_multi_query() looks like this:

if (mysqli_multi_query($link, 'CALL p()')) {
  do {
    if ($res = mysqli_store_result($link)) {
     while ($row = mysqli_fetch_assoc($res))
       var_dump($row);
     mysqli_free_result($res);
    }
 } while (mysqli_more_results($link) && mysqli_next_result($link));

} else {
  printf("Cannot call SP, [%d] %s\n", 
    mysqli_errno($link), mysqli_error($link));
}

I see you replacing mysqli_[real_]query() with mysqli_multi_query() but
I do not see the more_results()/next_result() loop etc. You continue
using the syntax for SPs which do not return a result set.

Ulf

------------------------------------------------------------------------

[2007-09-11 17:44:25] al dot smith at aeschi dot ch dot eu dot org

$query = "CALL count_runs(".$row["id"].", ".$minyear.",
".$maxyear.")";
$db->multi_query($query) or die ("Error in query: $query. " .
$db->error);

This was my query.

------------------------------------------------------------------------

[2007-09-11 15:54:04] garethjo at usc dot edu

No it doesn't, I tried it with both before sending in the bug report.

------------------------------------------------------------------------

[2007-09-11 10:00:30] uwendel at mysql dot com

Does using mysqli_multi_query() work for you? Currently you are using
mysqli_real_query() to call the SP. See also,
http://dev.mysql.com/doc/refman/5.1/en/call.html. If a stored procedure
produces result sets, you must use mysqli_multi_query(). 

Ulf

------------------------------------------------------------------------

[2007-09-09 10:42:13] [EMAIL PROTECTED]

Georg (or whoever maintains mysqli nowadays), check this out. Seems
like some regression bug between 5.2.3 / 5.2.4 crept in..

------------------------------------------------------------------------

The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at
    http://bugs.php.net/42548

-- 
Edit this bug report at http://bugs.php.net/?id=42548&edit=1

Reply via email to