This seems to be a Windows specific issue a few people have had, without a satisfactory outcome. I haven't tried the code on my Linux server yet.
When using a prepared statement to call a stored procedure multiple times crashes Apache.
The stored procedure appears to be returning two results, even for a simple SELECT * FROM users
making the next execute not work.
The workaround I'm using now is $mysqli->next_result();
between each execute.
My question, has anyone experienced this? And is there a fix, is this a bug or am I just doing something wrong?
Windows 7 wamp server -Apache 2.4.2 -Mysql 5.5.24 -PHP 5.4.3
/* MySQL code */
DELIMITER $$
PROCEDURE `get_data`(IN var1 VARCHAR(45),IN var2 VARCHAR(45) )
BEGIN
SELECT *
FROM data_table
WHERE `data1` = var1 AND `data2` = var2;
END
/* End MySQL code */
<?php
if( !($stmt = $mysqli->prepare("CALL get_data(?,?)")) )
die("Prepare failed: (" . $stmt->errno . ") " . $stmt->error);
$var1 = "some_data_1";
$var2 = "some_data_2";
if( $stmt->bind_param("ss", $var1, $var2) )
{
if( $stmt->execute() )
{
echo "Execute one complete.";
}
else
echo "Execute failed: (" . $stmt->errno . ") " . $stmt->error;
}
else
echo "Bind failed: (" . $stmt->errno . ") " . $stmt->error;
/* Current fix to clear stray results sent from the stored procedure */
$stmt->next_result();
$var2 = "some_data_555";
if( $stmt->bind_param("ss", $var1, $var2) )
{
if( $stmt->execute() )
{
echo "Execute two complete.";
}
else
echo "Execute failed: (" . $stmt->errno . ") " . $stmt->error;
}
else
echo "Bind failed: (" . $stmt->errno . ") " . $stmt->error;
?>
The code is obviously modified for debugging and stackoverflow.
The exact code with a normal query, IE SELECT * FROM users
works fine, until you call a stored procedure, IE CALL get_data(?,?)