MySQL Forums
Forum List  »  PHP

calling stored procedures from php problem...
Posted by: Calimlim Michael Angelo
Date: February 21, 2006 03:01AM

can any1 help me with my problem with calling stored procedures from php.....
the problem i having is the code sometimes gives an error sometimes it does not.......
can any1 help me find the problem.....
thanx for the help! :D

here is my code in mysql and php.....

mysql

create proceudre sp_test(out p_out char(255), out p_msg char(255), in p_val int)
begin
/*some sql queries here*/

if p_val > 15 then
set p_out = 1;
set p_msg = 'The number is greater than 15';
else
set p_out = 0;
set p_msg = 'The number is lesser than 15 ';
end if;
end

grant execute
on procedure db.sp_test
to usr@'host';

php

$val = 25; //can be any number.....

$db = new mysqli("host", "usr", "pwd", "db");

if (mysqli_connect_errno())
{
echo "Connection error";
exit();
}

$sp = "call sp_test(@out, @msg, ".$val.");";

if ($result = $db->query($sp))
{
if ($result = $db->query("select @out, @msg;"))
{
$row = $result->fetch_array(MYSQLI_BOTH);

echo $row[0]."<br>";
echo $row[1]."<br>"; //sometimes the query succeeds here
}
else
{
echo "Error!"; //sometimes gives an error here :(
}
}
else
{
echo "Error!";
}

Options: ReplyQuote


Subject
Written By
Posted
calling stored procedures from php problem...
February 21, 2006 03:01AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.