THE WORLD'S LARGEST WEB DEVELOPER SITE
HTMLCSSJAVASCRIPTSQLPHPBOOTSTRAPJQUERYANGULARXML
 

PHP mysqli_next_result() Function

PHP MySQLi Reference PHP MySQLi Reference

Example

Perform multiple queries against the database. Use mysqli_next_result() function to prepare the next result set:

<?php
$con=mysqli_connect("localhost","my_user","my_password","my_db");
// Check connection
if (mysqli_connect_errno())
  {
  echo "Failed to connect to MySQL: " . mysqli_connect_error();
  }

$sql = "SELECT Lastname FROM Persons ORDER BY LastName;";
$sql .= "SELECT Country FROM Customers";

// Execute multi query
if (mysqli_multi_query($con,$sql))
{
  do
    {
    // Store first result set
    if ($result=mysqli_store_result($con))
      {
      while ($row=mysqli_fetch_row($result))
        {
        printf("%s\n",$row[0]);
        }
      mysqli_free_result($con);
      }
    }
  while (mysqli_next_result($con));
}

mysqli_close($con);
?>

Definition and Usage

The mysqli_next_result() function prepares the next result set from mysqli_multi_query().


Syntax

mysqli_next_result(connection);

Parameter Description
connection Required. Specifies the MySQL connection to use

Technical Details

Return Value: TRUE on success. FALSE on failure
PHP Version: 5+

PHP MySQLi Reference PHP MySQLi Reference