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// www  .  j av a 2  s . c  om
$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);
?>




















Home »
  PHP Tutorial »
    Function reference »




PHP Array Functions
PHP Calendar Functions
PHP Class Functions
PHP Data Type Functions
PHP Date Functions
PHP File Functions
PHP Image Functions
PHP Math Functions
PHP MySQLi Functions
PHP SimpleXML Functions
PHP String Functions
PHP XML Functions
PHP Zip Functions