Possible Duplicate:
Can't return a result set in the given context
I am trying to call a basic stored procedure using PHP. But mysql produces an error like "PROCEDURE softland.getAllProducts can't return a result set in the given context".
Stored Procedure
DELIMITER //
CREATE PROCEDURE GetAllProducts()
BEGIN
SELECT * FROM products;
END //
DELIMITER ;
PHP code is
<?php
$con=mysql_connect("localhost","root","");
mysql_select_db("softland",$con);
$id = 1;
$result = mysql_query("call getAllProducts()");
echo $result;
if ($result === FALSE) {
die(mysql_error());
}
while($row=mysql_fetch_array($result)){
echo "<br>".$row['name'];
}
echo "Succees";
?>
Try this,
Function GetProducts($out)
{
$query.= "CREATE PROCEDURE GetAllProducts() ";
$query.= "BEGIN";
$query.= "SELECT * FROM products;";
$query.= "END";
return $query;
}
In the code put this,
$result = mysql_query(GetProducts());
Hope that works !!
I think the problem is that you're using the old mysql functions instead of the newer mysqli library.
Try following the examples on this manual page.
Well, this answer is straight from the php page on mysql_connect:
$this->con = mysql_connect($this->h,$this->u,$this->p,false,65536);
Which tells your mysql client to use multi-statement support (see also the mysql client constants: http://php.net/manual/en/mysql.constants.php#mysql.client-flags)