3

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";
 ?>
Community
  • 1
  • 1
Sunil
  • 61
  • 2
  • 6
  • 2
    Plz check the question update.. The error is "PROCEDURE softland.getAllProducts can't return a result set in the given context" – Sunil May 27 '12 at 14:20

3 Answers3

1

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)

Rahil Wazir
  • 10,007
  • 11
  • 42
  • 64
mabi
  • 5,279
  • 2
  • 43
  • 78
  • 1
    Thanks for your time . So please make it clear how can I solve the issue ? – Sunil May 27 '12 at 15:19
  • 1
    I have updated the code with $con=mysql_connect("localhost","root","",false,65536). But still showing the same error message – Sunil May 27 '12 at 15:23
0

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 !!

user1391670
  • 476
  • 5
  • 6
0

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.

grossvogel
  • 6,694
  • 1
  • 25
  • 36