Reputation: 309
this is my sp:
CREATE DEFINER=`root`@`localhost` PROCEDURE `getproductname`(in productid int , out productname varchar(200))
BEGIN
select product_name from product where product_id=productid ;
END
and this is my php code:
$mysqli = new mysqli(DB_HOST,DB_USER,DB_PWD,DB_NAME);
$mysqli->query("CALL getproductname(2049,@productname)") ;
$result = $mysqli->query("SELECT @productname");
while($row = $result->fetch_object()){
echo ($row[0]);
}
and this is error:
Fatal error: Call to a member function fetch_object() on a non-object in D:\WEB\book24ss\_res\sptest.php on line 19
why?
Upvotes: 0
Views: 139
Reputation: 83622
You have the following problems with your code:
out
parameter productname
inside your stored procedure.productname
, retrieving it by using SELECT @productname
would only result in a single value - there is no need to iterate over the result.CALL getproductname(2049,@productname)
will return the result set you'd get from the simple query select product_name from product where product_id=@productid
- you'd have to iterate over the result set you get back from calling your stored procedure.I think you have some error in reasoning regarding the usage and functioning of stored procedures.
Upvotes: 1