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

Avatar of undefined
Last Comment
happysunny
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

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of happysunny
happysunny
Flag of United States of America image

ASKER

I see...Does mysqli have to be configured on my VPS?  Can you give me an idea on how to go about that?
Avatar of ralmada
ralmada
Flag of Canada image

try

$rs = $mysqli->query( ‘CALL test()’ );
while($row = $rs->fetch_object())
{

 ... do something here ...

}
SOLUTION
Avatar of ralmada
ralmada
Flag of Canada image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
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/
Avatar of happysunny
happysunny
Flag of United States of America image

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

$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
Avatar of Nem Schlecht
Nem Schlecht
Flag of United States of America image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
Avatar of ralmada
ralmada
Flag of Canada image

>>Should I just make the switch to mysqli or can I stay with mysql?<<

switch to mysqli.
Avatar of happysunny
happysunny
Flag of United States of America image

ASKER

Thank you!
PHP
PHP

PHP is a widely-used server-side scripting language especially suited for web development, powering tens of millions of sites from Facebook to personal WordPress blogs. PHP is often paired with the MySQL relational database, but includes support for most other mainstream databases. By utilizing different Server APIs, PHP can work on many different web servers as a server-side scripting language.

125K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo