Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6202017
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T04:39:26+00:00 2026-05-24T04:39:26+00:00

I have the following PHP/MySQL code: function executeMultirowQuery($query) { $result = mysql_query($query); $table =

  • 0

I have the following PHP/MySQL code:

function executeMultirowQuery($query) {
   $result = mysql_query($query);
   $table = array(); 

   if ($result == false) {
      $error = mysql_error();
      echo $error;
   } else {
      while ($row = mysql_fetch_assoc($result)) {
         $table[] = $row;
      }
      mysql_free_result($result);
   }

   return $table;
}

It basically executes the given query, and returns the result as a multi-dimensional array.
The second call (and all subsequent calls) to this function result in a “Commands out of sync; you can’t run this command now” error from MySQL.

Since I’m calling mysql_free_result() before I return I don’t think its that I still have a request out there, but I can’t think of any other reason it might be failing.

Any ideas?

EDIT:
If it makes any difference, I’m using this function to call stored procedures like this:

function getGroups($groupTypeID) {
   echo "getGroups";
   $query = sprintf("CALL getGroups('%s');", mysql_real_escape_string($groupTypeID));

   return $this->executeMultirowQuery($query);
}

This is typical of the way the executeMultirowQuery() function is used.

EDIT:
Here is my connection code:

$this->link = mysql_connect($host, $user, $password);
$success = mysql_select_db($database);

if (!$this->link) {
   die('Could not connect: ' . mysql_error());
}

Also, here is a sample query from the stored procedure:

CREATE DEFINER=`blah`@`blah` PROCEDURE `getGroups`(
    IN inGroupTypeID INT )
BEGIN
   SELECT * FROM `db`.`Groups`
   WHERE GroupTypeID = inGroupTypeID;
END

Again, this is typical of how the function is being used. None of the stored procedures returns multiple results sets (which I understand doesn’t work in PHP/MySQL).

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T04:39:27+00:00Added an answer on May 24, 2026 at 4:39 am

    A stored procedure returns two resultsets – your data plus a count of the number of rows fetched so you need to call

    next_result() 
    

    after each db call.

    You’d also be better off using mysqli vs mysql (only the latest mysql extension supports sproc calls) then you can use the faster fetch_all method to populate your array.

    $table = $result->fetch_all(MYSQLI_ASSOC);
    

    Hope this helps

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have code with the following form: <?php function doSomething{ //Do stuff with MySQL
This is for MySQL and PHP I have a table that contains the following
I have to following code: http://www.nomorepasting.com/getpaste.php?pasteid=22987 If PHPSESSID is not already in the table
I have the following jquery code: $(.rotateNews).load(/load_news.php); var refreshId = setInterval(function() { $(.rotateNews).load('/load_news.php?newsID='); },
I have the following php code, which has been snipped for brevity. I am
I have the following code: http://www.nomorepasting.com/getpaste.php?pasteid=22615 Which is called by the javascript mentioned in
I'm using php and I have the following code to convert an absolute path
I have the following code: <td colspan=7height=200 valign=top> <iframe id=myframe name=myframe src=index.php?page=1 width=810 height=100
I have the following code: public function createNewGuide($userID,$guideName) { $sql = INSERT INTO myTable(name,
I have the following code: function dbInsert() { global $dbcon, $dbtable; global $inputData; $sqlQuery

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.