happysunny
asked on
Basic Stored Procedures
Hello,
I am learning about stored routines and am having a hard time getting results. I have this in mysql:
How would I call on the results? I've tried the following and can't get an answer, so obviously I am doing it wrong.
Please enlighten me! Thank you in advance for any help!
I am learning about stored routines and am having a hard time getting results. I have this in mysql:
DROP PROCEDURE `test`//
CREATE DEFINER=`user`@`localhost` PROCEDURE `test`()
BEGIN
SELECT * FROM `database`.`tablecds`;
END
How would I call on the results? I've tried the following and can't get an answer, so obviously I am doing it wrong.
$sql = "CALL test();" or die(mysql_error());
mysql_query($sql, $con);
$sql = "SELECT @cd;";
$result = mysql_query($sql, $con);
$row = mysql_fetch_assoc($result);
$echo= $row['cd'];
Please enlighten me! Thank you in advance for any help!
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I see...Does mysqli have to be configured on my VPS? Can you give me an idea on how to go about that?
try
$rs = $mysqli->query( ‘CALL test()’ );
while($row = $rs->fetch_object())
{
... do something here ...
}
$rs = $mysqli->query( ‘CALL test()’ );
while($row = $rs->fetch_object())
{
... do something here ...
}
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
You can use store procedure with MySQL, MySQLi and ADO.
More information can be found in this link:
http://www.joeyrivera.com/ 2009/using -mysql-sto red-proced ures-with- php-mysqlm ysqlipdo/
More information can be found in this link:
http://www.joeyrivera.com/
ASKER
Yes, if I can stick with mysql instead of mysqli, I'd like to do that. But is it possible?
I tried to do this from the link...
but I got the following error:
"Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource"
Should I just make the switch to mysqli or can I stay with mysql?
I tried to do this from the link...
$rs = mysql_query( 'CALL test()' );
while($row = mysql_fetch_assoc($rs))
{
debug($row);
}
but I got the following error:
"Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource"
Should I just make the switch to mysqli or can I stay with mysql?
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
>>Should I just make the switch to mysqli or can I stay with mysql?<<
switch to mysqli.
switch to mysqli.
ASKER
Thank you!
If you post the exact result or error, that will be helpful to solve this issue.
Anyway, this link very useful and show different way to call stored procedure from PHP:
http://www.joeyrivera.com/