PHP mysqli_more_results() Function

Beginner
5 min read
Updated: Nov 2026
3 examples
MySQLi

Definition

In PHP, mysqli_more_results() returns true when more results are still waiting from a multi-statement query started with mysqli_multi_query().

Use it in a loop with mysqli_next_result() to walk every result set. Pair with mysqli_store_result() or mysqli_use_result() when the current statement produced rows.

Syntax

Call mysqli_more_results() with the values you need. Start with this line.

PHP
$more = mysqli_more_results($mysqli);
CallWhat it does
mysqli_more_results($mysqli)True if another result remains after multi_query.
while (mysqli_more_results($mysqli)) { mysqli_next_result($mysqli); }Advances until every result is consumed.
if (mysqli_more_results($mysqli)) { /* handle next */ }Branches when another batch is waiting.

Single mysqli_query() calls do not need this. It belongs to the multi_query → more_results → next_result workflow. Leaving unread multi-results blocks later queries with "out of sync" errors.

Library declarations
PHP
mysqli_more_results(mysqli $mysql): bool

Parameters

ParameterDescription
mysqlRequired. The mysqli connection that ran mysqli_multi_query().

Return Value

Return ValueDescription
booltrue if more results are available; false when the batch is finished.

PHP Examples

Example 1 — Detect Extra Results After Multi Query

Run two statements and check whether more results remain after the first.

PHP
<?php
$mysqli = mysqli_connect("localhost", "demo_user", "demo_pass", "app_db");

mysqli_multi_query($mysqli, "SELECT 1; SELECT 2;");

$result = mysqli_store_result($mysqli);
if ($result) {
    mysqli_free_result($result);
}

echo mysqli_more_results($mysqli) ? "More waiting." : "Done.", PHP_EOL;

mysqli_close($mysqli);

How It Works

  1. mysqli_multi_query() sends two SELECTs at once.
  2. store_result() reads the first result set.
  3. mysqli_more_results() is still true because SELECT 2 is pending.
  4. You must call next_result() before reading the second set.

Example 2 — Drain Every Result

Loop until more_results is false so the connection is clean again.

PHP
<?php
$mysqli = mysqli_connect("localhost", "demo_user", "demo_pass", "app_db");
mysqli_multi_query($mysqli, "SELECT 1 AS n; SELECT 2 AS n;");

$sets = 0;
do {
    if ($result = mysqli_store_result($mysqli)) {
        $sets++;
        mysqli_free_result($result);
    }
} while (mysqli_more_results($mysqli) && mysqli_next_result($mysqli));

echo "Result sets: ", $sets, PHP_EOL;

mysqli_close($mysqli);

How It Works

  1. The do/while pattern is the standard multi-query drain loop.
  2. store_result() loads each SELECT set when present.
  3. more_results() asks if another set exists.
  4. next_result() moves the connection to that next set.

Example 3 — Single Query Needs No more_results

A normal mysqli_query() leaves more_results false.

PHP
<?php
$mysqli = mysqli_connect("localhost", "demo_user", "demo_pass", "app_db");
mysqli_query($mysqli, "SELECT 1");

var_dump(mysqli_more_results($mysqli));

mysqli_close($mysqli);

How It Works

  1. Only one statement was sent.
  2. more_results() returns false.
  3. No next_result() loop is required.
  4. Use multi_query only when you truly need multiple statements.

Frequently Asked Questions

Whether another result from mysqli_multi_query() is still waiting on the connection.
Inside the multi-query drain loop, usually as the while condition with mysqli_next_result().
Later queries often fail with "Commands out of sync" until you finish or close the connection.
No. It only answers yes or no. Use next_result() plus store_result()/use_result() to read data.
Almost never. It is for multi-statement batches.

Next: mysqli_multi_query()

mysqli_multi_query() sends one or more SQL statements separated by semicolons in a single .

mysqli_multi_query() tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

8 people found this page helpful