• PHP Video Tutorials

PHP mysqli_more_results() Function



Definition and Usage

The mysqli_more_results() function verifies whether there are more results in the last executed multi query.

Syntax

mysqli_more_results($con)

Parameters

Sr.No Parameter & Description
1

con(Mandatory)

This is an object representing a connection to MySQL Server.

Return Values

The mysqli_more_results() function returns true if there are more resultsets (or, errors) and it returns false if there are no more result sets.

PHP Version

This function was first introduced in PHP Version 5 and works works in all the later versions.

Example

Following example demonstrates the usage of the mysqli_more_results() function (in procedural style) −

<?php
   //Creating a connection
   $con = mysqli_connect("localhost", "root", "password", "test");

   //Executing the multi query
   $query = "SELECT * FROM players;SELECT * FROM emp";
   mysqli_multi_query($con, $query);

   do{
      $result = mysqli_use_result($con);
      while($row = mysqli_fetch_row($result)){
         print("Name: ".$row[0]."\n");
         print("Age: ".$row[1]."\n");
         print("\n");
      }
      if(mysqli_more_results($con)){
         print("::::::::::::::::::::::::::::::\n");
      }
   }while(mysqli_next_result($con));
   mysqli_close($con);
?>

This will produce following result −

Name: Dhavan
Age: 33

Name: Rohit
Age: 28

Name: Kohli
Age: 25

::::::::::::::::::::::::::::::
Name: Raju
Age: 25

Name: Rahman
Age: 30

Name: Ramani
Age: 22

Example

In object oriented style the syntax of this function is $con->more_results(); Following is the example of this function in object oriented style $minus;

<?php
   $con = new mysqli("localhost", "root", "password", "test");

   //Multi query
   $res = $con->multi_query("SELECT * FROM players;SELECT * FROM emp");

   do {
      $result = $con->use_result();
      while($row = $result->fetch_row()){
         print("Name: ".$row[0]."\n");
         print("Age: ".$row[1]."\n");
         print("\n");
      }
      if($con->more_results()){
         print("::::::::::::::::::::::::::::::\n");
      }
   } while ($con->next_result());

   //Closing the connection
   $res = $con -> close();
?>

This will produce following result −

Name: Dhavan
Age: 33

Name: Rohit
Age: 28

Name: Kohli
Age: 25

::::::::::::::::::::::::::::::
Name: Raju
Age: 25

Name: Rahman
Age: 30

Name: Ramani
Age: 22
php_function_reference.htm
Advertisements