Link to home
Start Free TrialLog in
Avatar of happysunny
happysunnyFlag for United States of America

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:

DROP PROCEDURE `test`//
CREATE DEFINER=`user`@`localhost` PROCEDURE `test`()
BEGIN
SELECT * FROM `database`.`tablecds`;
END

Open in new window


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'];

Open in new window


Please enlighten me!  Thank you in advance for any help!
Avatar of Ahmed Merghani
Ahmed Merghani
Flag of Sudan image

Hi happysunny,

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/2009/using-mysql-stored-procedures-with-php-mysqlmysqlipdo/
ASKER CERTIFIED SOLUTION
Avatar of Nem Schlecht
Nem Schlecht
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of happysunny

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

}
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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-stored-procedures-with-php-mysqlmysqlipdo/
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...

$rs = mysql_query( 'CALL test()' );
while($row = mysql_fetch_assoc($rs))
{
debug($row);
}

Open in new window


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
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
>>Should I just make the switch to mysqli or can I stay with mysql?<<

switch to mysqli.
Thank you!