PHP Tutorial - PHP mysqli_next_result() Function






Definition

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

Syntax

Object oriented style

bool mysqli::next_result ( void )

Procedural style

bool mysqli_next_result ( mysqli $link )

Parameter

ParameterIs requiredDescription
connectionRequired.MySQL connection to use

Return

It returns TRUE on success and FALSE on failure.

Example

The following code uses mysqli_next_result() function to prepare the next result set.


<?php//w ww .  j a  v  a2  s . com
$con=mysqli_connect("localhost","my_user","my_password","my_db");

if (mysqli_connect_errno($con)){
  echo "Failed to connect to MySQL: " . mysqli_connect_error();
}

$sql = "SELECT name FROM emp;SELECT Country FROM emp";


if (mysqli_multi_query($con,$sql)){
  do{
    // Store first result set
    if ($result=mysqli_store_result($con)){
      while ($row=mysqli_fetch_row($result)){
        print $row[0];
        print "\n";
      }      
    }
  }while (mysqli_next_result($con));
}

mysqli_close($con);
?>