PROCEDURE can’t return a result set in the given context

Posted on June 22nd, 2010 in Uncategorized by Brandon

I ran into a problem today when dealing with a very simple SQL Query. The query simply calls a stored procedure on the MySQL server. This is a trivial app, so I was using the very basic mysql_connect(), mysql_query() functions. The result wasn’t being returned an mysql_error() was saying that the error was:

PROCEDURE db.procedure_name can't return a result set in the given context

Of course ‘db.procedure_name’ was the actual name of the procedure I was calling. Googling for the error seemed to indicate that the MySQL client library was old, but this is on a fairly modern CentOS 5.5 server with the php-mysql package at version 5.1.6.

After a bit of experimenting, I found that I was able to change to using the mysql improved versions of the PHP functions and that worked fine

     $dbconn = mysql_connect($dbhost, $dbuser, $dbpass);
     $result = mysql_query("CALL db.procedure_name('arg1', 'arg2', 'arg3')", $dbconn)
     $row    = mysql_fetch_assoc($result);


    $dbconn = mysqli_connect($dbhost, $dbuser, $dbpass);
    $result = mysqli_query($dbconn, "CALLdb.procedure_name('arg1', 'arg2', 'arg3')");
    $row    = mysqli_fetch_assoc($result);

Note that changing from mysql_query to myqli_query needs the parameters reversed.

After making that change I’m able to run the stored procedure correctly.

4 Responses to 'PROCEDURE can’t return a result set in the given context'

Subscribe to comments with RSS or TrackBack to 'PROCEDURE can’t return a result set in the given context'.

  1. Abhilash said,

    on July 12th, 2011 at 5:50 am

    Hi Thanks for the help its working great.

  2. on August 16th, 2011 at 8:39 pm

    Hi, thank you very much, I were googling for this since morning, you save my time.many thanks.

  3. cuberhead said,

    on January 15th, 2012 at 11:33 am

    Thank u very much.. I was just about to get frustrated.. But this worked perfectly.

  4. Jose Mayorga said,

    on December 3rd, 2012 at 6:38 pm


    I’m using the mysql_query functions, and it works perfectly… Well, kind of. The thing is that I have two PHP files that make a call to a Stored Procedure. One file success, and the other returns that error “can’t return a result set in the given context”… Do you have any idea what could I be missing?

Post a comment

Please copy the string RFUdMh to the field below: