php problems calling stored mysql procudure

Posted on 2011-02-14
Last Modified: 2012-08-13
Hi Experts,

I have the following code in PHP:
$mysql = mysql_connect("localhost","myuser","password",false,65536);
mysql_select_db("mydb", $mysql);
$rs = mysql_query( $sql )
die (mysql_errno());

Open in new window

Re mysql, 'myuser' has execute privileges on this procedure - ie if I call this through the mysql console it works.  However, when I call this procedure using php it sometimes works and sometimes doesn't. How do I debug (using php) why this isn't being called?

Question by:jagku
  • 2
  • 2
LVL 16

Accepted Solution

Chris Harte earned 500 total points
ID: 34887830
You need to echo the errno. Though an intermittent problem may mean a dodgy connection is timing out.

if (!mysql_query( $sql ))
     echo mysql_errno();

Expert Comment

ID: 34887835
Did you get any error code (tru mysql_errno)? Or simply the mysql_query function isn't being called?
Try inserting and ECHO (echo "Line 3:" . $sql;) between lines 3 and 4 to see if that section of code has been reached.

Author Comment

ID: 34887893

Thanks. I get error 1312.
My procedure doesn't return anything.
Any ideas how I can overcome this?

I thought the 65536 parameter should have fixed this - but it hasn't.

LVL 16

Expert Comment

by:Chris Harte
ID: 34887977
Try using mysqli, this is an improved interface and should work.

Author Closing Comment

ID: 34888023
I think the problem was that I had a select in the stored procedure that I was using for debugging - which was probably baffling the php-mysql API.
I have commented this out and it seems to be working.


Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now