Hi guys how can I call the procedure using php ?
Code:<?php
include 'config.php';
include 'opendb.php';
$qry = mysql_query("CALL HelloWorld()");
$row = mysql_fetch_array($qry, MYSQL_NUM);
echo "$row[0]";
include 'closedb.php';
?>
Printable View
Hi guys how can I call the procedure using php ?
Code:<?php
include 'config.php';
include 'opendb.php';
$qry = mysql_query("CALL HelloWorld()");
$row = mysql_fetch_array($qry, MYSQL_NUM);
echo "$row[0]";
include 'closedb.php';
?>
What's the problem?
By the way, those quotes around $row[0] are superflous.
Also you should consider using a proper data access library. PDO for PHP 5; MDB2 or mysqli for PHP 4.
The problem is it does not print out my procedure. In the helloworld procedure, the select * from tablename. that's all i have. I just wanna test to see if I can call using php. But nothing is produced. I am using php5, and mysql 5 version too. Help?
Echo mysql_error() and see if there is any problem on the DB side. Run the query in something like phpMyAdmin and see if it returns anything.
try this... same code, made some changes..
PHP Code:<?php
include ('config.php');
include ('opendb.php');
$qry = mysql_query(CALL HelloWorld());
$row = mysql_fetch_array($qry, MYSQL_NUM);
echo $row[0];
include ('closedb.php');
?>
Sorry Dylan, I had to edit your post because the highlight tags made a mess of the [ character.
Anyway, that won't work - CALL is a MySQL keyword and should be in the query text. As it is, that's a syntax error.
The db is fine if I change that statement from CALL to select * from tablename. It's not working with CALL at all.
Here is my procedure
CREATE PROCEDURE HelloWorld()
SELECT * from tablename;
What happens if you try my suggestions in post #4?
Hello, I put in that mysql_error("failed quering"). So I got failed querying on the page.
you don't put text inside of the parameter for mysql_error(), it's an optional parameter to identify what link you want to display the error for. you should probably look up the function on PHP.net if you have no idea how to use it, before plugging random things into it.
more informationPHP Code:<?php
//like this:
mysql_query($sql) or die(mysql_error());
//or:
mysql_query($sql);
echo mysql_error();
?>
This is what I got after I put mysql_error():
PROCEDURE tablename.Helloworld can't return a result set in the given context
How is Helloworld defined, then?