|
-
Apr 11th, 2007, 07:09 PM
#1
Thread Starter
Frenzied Member
[RESOLVED] calling store procedure
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';
?>
-
Apr 11th, 2007, 07:12 PM
#2
Re: calling store procedure
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.
-
Apr 11th, 2007, 07:18 PM
#3
Thread Starter
Frenzied Member
Re: calling store procedure
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?
-
Apr 11th, 2007, 07:24 PM
#4
Re: calling store procedure
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.
-
Apr 11th, 2007, 11:20 PM
#5
Re: calling store procedure
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');
?>
Last edited by penagate; Apr 11th, 2007 at 11:26 PM.
Reason: [highlight=php] => [php]
My usual boring signature: Something
-
Apr 11th, 2007, 11:27 PM
#6
Re: calling store procedure
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.
-
Apr 12th, 2007, 12:36 AM
#7
Thread Starter
Frenzied Member
Re: calling store procedure
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;
-
Apr 12th, 2007, 12:41 AM
#8
Re: calling store procedure
What happens if you try my suggestions in post #4?
-
Apr 12th, 2007, 03:57 PM
#9
Thread Starter
Frenzied Member
Re: calling store procedure
Hello, I put in that mysql_error("failed quering"). So I got failed querying on the page.
-
Apr 12th, 2007, 04:02 PM
#10
Re: calling store procedure
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.
PHP Code:
<?php
//like this:
mysql_query($sql) or die(mysql_error());
//or:
mysql_query($sql);
echo mysql_error();
?>
more information
-
Apr 12th, 2007, 05:53 PM
#11
Thread Starter
Frenzied Member
Re: calling store procedure
This is what I got after I put mysql_error():
PROCEDURE tablename.Helloworld can't return a result set in the given context
-
Apr 15th, 2007, 03:57 AM
#12
Re: [RESOLVED] calling store procedure
How is Helloworld defined, then?
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|