473,388 Members | 1,177 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,388 software developers and data experts.

Stored procedures, MySQL, and PHP

Hello PHP group,

Could someone help me out? I have PHP 5.2, Apache 2.0, and MySQL 5.0
running on Linux (Redhat Fedora Core 6).

All that works fine. I would like to be able to "call" a stored
procedure from a PHP program, and
run a stored procedure. I have yet to figure out the proper way to do
this. My stored procedures work fine from the mysql command line
using syntax: "call sp_min_record (101);"

But when I try to do the same thing within my PHP page - no luck I get
an error.

Here is my stored procedure code:

DELIMITER $$

DROP PROCEDURE IF EXISTS `portfolios`.`sp_min_record` $$

CREATE DEFINER=`ewh`@`localhost` PROCEDURE
`portfolios`.`sp_min_record`
(IN folio INT)
BEGIN
SELECT MIN(id) INTO minr FROM images3 WHERE p = folio;
END$$

DELIMITER ;

and here is how I am trying to call it from php:

$dbconnect = db_connect('portfolios') or trigger_error("Error
Connecting to Database: "
. mysql_error(), E_USER_ERROR);

$help = @mysql_query("call sp_min_record ($folio)");
$rowx = @mysql_fetch_assoc($help);

$minrec = $rowx[0];

but I get no value returned. How am I supposed to do this
(correctly :))?
Thanks,
eholz1

Apr 2 '07 #1
7 5825
eholz1 wrote:
Hello PHP group,

Could someone help me out? I have PHP 5.2, Apache 2.0, and MySQL 5.0
running on Linux (Redhat Fedora Core 6).

All that works fine. I would like to be able to "call" a stored
procedure from a PHP program, and
run a stored procedure. I have yet to figure out the proper way to do
this. My stored procedures work fine from the mysql command line
using syntax: "call sp_min_record (101);"

But when I try to do the same thing within my PHP page - no luck I get
an error.

Here is my stored procedure code:

DELIMITER $$

DROP PROCEDURE IF EXISTS `portfolios`.`sp_min_record` $$

CREATE DEFINER=`ewh`@`localhost` PROCEDURE
`portfolios`.`sp_min_record`
(IN folio INT)
BEGIN
SELECT MIN(id) INTO minr FROM images3 WHERE p = folio;
END$$

DELIMITER ;

and here is how I am trying to call it from php:

$dbconnect = db_connect('portfolios') or trigger_error("Error
Connecting to Database: "
. mysql_error(), E_USER_ERROR);

$help = @mysql_query("call sp_min_record ($folio)");
$rowx = @mysql_fetch_assoc($help);

$minrec = $rowx[0];

but I get no value returned. How am I supposed to do this
(correctly :))?
Thanks,
eholz1
First of all, get rid of the '@' characters. Then check the results of
mysql_query to see if you got an error. If so, print the error and see
what's actually happening.

Pet Peeve: Why do people disable error reporting with '@', don't check
the results of their calls, then come asking why it isn't working?

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Apr 2 '07 #2
On Apr 2, 9:10 am, Jerry Stuckle <jstuck...@attglobal.netwrote:
eholz1 wrote:
Hello PHP group,
Could someone help me out? I have PHP 5.2, Apache 2.0, and MySQL 5.0
running on Linux (Redhat Fedora Core 6).
All that works fine. I would like to be able to "call" a stored
procedure from a PHP program, and
run a stored procedure. I have yet to figure out the proper way to do
this. My stored procedures work fine from the mysql command line
using syntax: "call sp_min_record (101);"
But when I try to do the same thing within my PHP page - no luck I get
an error.
Here is my stored procedure code:
DELIMITER $$
DROP PROCEDURE IF EXISTS `portfolios`.`sp_min_record` $$
CREATE DEFINER=`ewh`@`localhost` PROCEDURE
`portfolios`.`sp_min_record`
(IN folio INT)
BEGIN
SELECT MIN(id) INTO minr FROM images3 WHERE p = folio;
END$$
DELIMITER ;
and here is how I am trying to call it from php:
$dbconnect = db_connect('portfolios') or trigger_error("Error
Connecting to Database: "
. mysql_error(), E_USER_ERROR);
$help = @mysql_query("call sp_min_record ($folio)");
$rowx = @mysql_fetch_assoc($help);
$minrec = $rowx[0];
but I get no value returned. How am I supposed to do this
(correctly :))?
Thanks,
eholz1

First of all, get rid of the '@' characters. Then check the results of
mysql_query to see if you got an error. If so, print the error and see
what's actually happening.

Pet Peeve: Why do people disable error reporting with '@', don't check
the results of their calls, then come asking why it isn't working?

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstuck...@attglobal.net
==================
Hello Jerry et al,

removed the offending @'s!! No error messages. No results either!
It seems that my query (stored procedure is not really being called
correctly from my php code. As I mentioned earlier, it produces a
result from the mysql command line. I could cheat, and use the old
"SELECT MIN(id) from table where val = 101;", but a stored procedure
seems much cooler.

Apr 2 '07 #3
eholz1 wrote:
On Apr 2, 9:10 am, Jerry Stuckle <jstuck...@attglobal.netwrote:
>eholz1 wrote:
>>Hello PHP group,
Could someone help me out? I have PHP 5.2, Apache 2.0, and MySQL 5.0
running on Linux (Redhat Fedora Core 6).
All that works fine. I would like to be able to "call" a stored
procedure from a PHP program, and
run a stored procedure. I have yet to figure out the proper way to do
this. My stored procedures work fine from the mysql command line
using syntax: "call sp_min_record (101);"
But when I try to do the same thing within my PHP page - no luck I get
an error.
Here is my stored procedure code:
DELIMITER $$
DROP PROCEDURE IF EXISTS `portfolios`.`sp_min_record` $$
CREATE DEFINER=`ewh`@`localhost` PROCEDURE
`portfolios`.`sp_min_record`
(IN folio INT)
BEGIN
SELECT MIN(id) INTO minr FROM images3 WHERE p = folio;
END$$
DELIMITER ;
and here is how I am trying to call it from php:
$dbconnect = db_connect('portfolios') or trigger_error("Error
Connecting to Database: "
. mysql_error(), E_USER_ERROR);
$help = @mysql_query("call sp_min_record ($folio)");
$rowx = @mysql_fetch_assoc($help);
$minrec = $rowx[0];
but I get no value returned. How am I supposed to do this
(correctly :))?
Thanks,
eholz1
First of all, get rid of the '@' characters. Then check the results of
mysql_query to see if you got an error. If so, print the error and see
what's actually happening.

Pet Peeve: Why do people disable error reporting with '@', don't check
the results of their calls, then come asking why it isn't working?

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstuck...@attglobal.net
==================

Hello Jerry et al,

removed the offending @'s!! No error messages. No results either!
It seems that my query (stored procedure is not really being called
correctly from my php code. As I mentioned earlier, it produces a
result from the mysql command line. I could cheat, and use the old
"SELECT MIN(id) from table where val = 101;", but a stored procedure
seems much cooler.
And what about the second half of my question - what is the result of
the query? Is mysql_query returning false? Or is it returning a result
set? And if the former, what's the error (hint: mysql_error()).
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Apr 3 '07 #4
eholz1 wrote:
Hello PHP group,

Could someone help me out? I have PHP 5.2, Apache 2.0, and MySQL 5.0
running on Linux (Redhat Fedora Core 6).

All that works fine. I would like to be able to "call" a stored
procedure from a PHP program, and
run a stored procedure. I have yet to figure out the proper way to do
this. My stored procedures work fine from the mysql command line
using syntax: "call sp_min_record (101);"

But when I try to do the same thing within my PHP page - no luck I get
an error.

Here is my stored procedure code:

DELIMITER $$

DROP PROCEDURE IF EXISTS `portfolios`.`sp_min_record` $$

CREATE DEFINER=`ewh`@`localhost` PROCEDURE
`portfolios`.`sp_min_record`
(IN folio INT)
BEGIN
SELECT MIN(id) INTO minr FROM images3 WHERE p = folio;
END$$

DELIMITER ;

and here is how I am trying to call it from php:

$dbconnect = db_connect('portfolios') or trigger_error("Error
Connecting to Database: "
. mysql_error(), E_USER_ERROR);

$help = @mysql_query("call sp_min_record ($folio)");
$rowx = @mysql_fetch_assoc($help);

$minrec = $rowx[0];

but I get no value returned. How am I supposed to do this
(correctly :))?
Thanks,
eholz1
You fetch an associative array and then access $rowx[0].
I'd expect a field name instead.

HTH

Sh.
Apr 3 '07 #5
On Apr 2, 5:51 pm, Jerry Stuckle <jstuck...@attglobal.netwrote:
eholz1wrote:
On Apr 2, 9:10 am, Jerry Stuckle <jstuck...@attglobal.netwrote:
>eholz1wrote:
Hello PHP group,
Could someone help me out? I have PHP 5.2, Apache 2.0, and MySQL 5.0
running on Linux (Redhat Fedora Core 6).
All that works fine. I would like to be able to "call" a stored
procedure from a PHP program, and
run a stored procedure. I have yet to figure out the proper way to do
this. My stored procedures work fine from the mysql command line
using syntax: "call sp_min_record (101);"
But when I try to do the same thing within my PHP page - no luck I get
an error.
Here is my stored procedure code:
DELIMITER $$
DROP PROCEDURE IF EXISTS `portfolios`.`sp_min_record` $$
CREATE DEFINER=`ewh`@`localhost` PROCEDURE
`portfolios`.`sp_min_record`
(IN folio INT)
BEGIN
SELECT MIN(id) INTO minr FROM images3 WHERE p = folio;
END$$
DELIMITER ;
and here is how I am trying to call it from php:
$dbconnect = db_connect('portfolios') or trigger_error("Error
Connecting to Database: "
. mysql_error(), E_USER_ERROR);
$help = @mysql_query("call sp_min_record ($folio)");
$rowx = @mysql_fetch_assoc($help);
$minrec = $rowx[0];
but I get no value returned. How am I supposed to do this
(correctly :))?
Thanks,
eholz1
First of all, get rid of the '@' characters. Then check the results of
mysql_query to see if you got an error. If so, print the error and see
what's actually happening.
Pet Peeve: Why do people disable error reporting with '@', don't check
the results of their calls, then come asking why it isn't working?
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstuck...@attglobal.net
==================
Hello Jerry et al,
removed the offending @'s!! No error messages. No results either!
It seems that my query (stored procedure is not really being called
correctly from my php code. As I mentioned earlier, it produces a
result from the mysql command line. I could cheat, and use the old
"SELECT MIN(id) from table where val = 101;", but a stored procedure
seems much cooler.

And what about the second half of my question - what is the result of
the query? Is mysql_query returning false? Or is it returning a result
set? And if the former, what's the error (hint: mysql_error()).

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstuck...@attglobal.net
==================
The query is returning false. Here is the error (sorry for not doing
this FIRST!!!)
Fatal Error: Stored Procedure Error: PROCEDURE
portfolios.sp_min_record can't return a result set in the given
context (# 256).

I seem to have this error everytime I get the bright idea to use a
stored procedure that takes data or returns data. I am currently
using the "SELECT min(id) INTO minval FROM xxx" as above, if I call
this sp from the command line I get no result! So I am guessing wrong
syntax??? If I take the "INTO" out of the and use this SELECT MIN(id)
FROM images3 WHERE p = pval; I get a result from the command line, and
the error above when run from the PHP page.

Thanks for the info on this (as always)
eholz1
Apr 3 '07 #6
eholz1 wrote:
On Apr 2, 5:51 pm, Jerry Stuckle <jstuck...@attglobal.netwrote:
>eholz1wrote:
>>On Apr 2, 9:10 am, Jerry Stuckle <jstuck...@attglobal.netwrote:
eholz1wrote:
Hello PHP group,
Could someone help me out? I have PHP 5.2, Apache 2.0, and MySQL 5.0
running on Linux (Redhat Fedora Core 6).
All that works fine. I would like to be able to "call" a stored
procedure from a PHP program, and
run a stored procedure. I have yet to figure out the proper way to do
this. My stored procedures work fine from the mysql command line
using syntax: "call sp_min_record (101);"
But when I try to do the same thing within my PHP page - no luck I get
an error.
Here is my stored procedure code:
DELIMITER $$
DROP PROCEDURE IF EXISTS `portfolios`.`sp_min_record` $$
CREATE DEFINER=`ewh`@`localhost` PROCEDURE
`portfolios`.`sp_min_record`
(IN folio INT)
BEGIN
SELECT MIN(id) INTO minr FROM images3 WHERE p = folio;
END$$
DELIMITER ;
and here is how I am trying to call it from php:
$dbconnect = db_connect('portfolios') or trigger_error("Error
Connecting to Database: "
. mysql_error(), E_USER_ERROR);
$help = @mysql_query("call sp_min_record ($folio)");
$rowx = @mysql_fetch_assoc($help);
$minrec = $rowx[0];
but I get no value returned. How am I supposed to do this
(correctly :))?
Thanks,
eholz1
First of all, get rid of the '@' characters. Then check the results of
mysql_query to see if you got an error. If so, print the error and see
what's actually happening.
Pet Peeve: Why do people disable error reporting with '@', don't check
the results of their calls, then come asking why it isn't working?
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstuck...@attglobal.net
==================
Hello Jerry et al,
removed the offending @'s!! No error messages. No results either!
It seems that my query (stored procedure is not really being called
correctly from my php code. As I mentioned earlier, it produces a
result from the mysql command line. I could cheat, and use the old
"SELECT MIN(id) from table where val = 101;", but a stored procedure
seems much cooler.
And what about the second half of my question - what is the result of
the query? Is mysql_query returning false? Or is it returning a result
set? And if the former, what's the error (hint: mysql_error()).

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstuck...@attglobal.net
==================

The query is returning false. Here is the error (sorry for not doing
this FIRST!!!)
Fatal Error: Stored Procedure Error: PROCEDURE
portfolios.sp_min_record can't return a result set in the given
context (# 256).

I seem to have this error everytime I get the bright idea to use a
stored procedure that takes data or returns data. I am currently
using the "SELECT min(id) INTO minval FROM xxx" as above, if I call
this sp from the command line I get no result! So I am guessing wrong
syntax??? If I take the "INTO" out of the and use this SELECT MIN(id)
FROM images3 WHERE p = pval; I get a result from the command line, and
the error above when run from the PHP page.

Thanks for the info on this (as always)
eholz1

Well, it looks like a problem with your SP. I'd recommend following up
in comp.databases.mysql. Try to get it to work from the command line first.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Apr 3 '07 #7
On 2 Apr 2007 08:33:05 -0700, "eholz1" <ew****@gmail.comwrote:
>$help = @mysql_query("call sp_min_record ($folio)");
I was under the impression that only the "mysqli" extension could call MySQL
stored procedures, and that the older "mysql" extension only handles plain SQL.

--
Andy Hassall :: an**@andyh.co.uk :: http://www.andyh.co.uk
http://www.andyhsoftware.co.uk/space :: disk and FTP usage analysis tool
Apr 3 '07 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Charles Parker | last post by:
Does MySQL have support for calling functions in C/C++ DLLs from trigger scripts similar to the Extended Stored Procedures functionality provided in SQL Sever? Thanks. Charles... -- MySQL...
0
by: Chrisbarbers | last post by:
--part1_108.256bef7d.2c5af59f_boundary Content-Type: text/plain; charset="ISO-8859-1" Content-Transfer-Encoding: quoted-printable Hi =A0 I have purchased a package that uses ASP and SQL,...
3
by: Ben | last post by:
Dear MySQL experts, I have a website that is using MS SQL Server 2000 with ASP scripting. I want to switch over to MySQL, but I'm just sticking my toes in the water at the moment to see if it...
3
by: Marty | last post by:
Is there an issue with stored procedure and mySQL v5.0.18 ? We are programming an application that need stored procedures and triggers and our programmer can't make them work, is it a know issue...
1
by: E.T. Grey | last post by:
Hi All, Despite spending the past six to seven hours perusing the docs on the mySQl site, I still have questions unanswered, and have been unable to get any help. I am familiar with Sybase, some...
2
by: bshumsky06 | last post by:
Hi, I am trying to create stored procedures in MySQL. Does anyone have a suggestion on a good IDE to use. I have been working with the MySQL Query Browser but it generates errors very often and...
1
by: Radhakrishnans | last post by:
hai friends i am new to java and mysql.i have created stored procedures in mysql.Now i want to call that stored procedures in java.All works fine.but it show the following error. unreported...
0
by: Bruno Barberi Gnecco | last post by:
I'm using stored procedures in a PHP site, with mysql. I'm having problems with stored procedures. Of the two I'm using, one works all the time, consistently. The other works correctly, but the...
1
by: Muhammad Intikhab Qaiser | last post by:
Hi I am developing a parser to parse the stored procedure and function definition of MySQL.I need to extract the names of stored procedures,functions and tables which are being used in any...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.