PHP | mysqli_more_results() Function

PHP mysqli_more_results() Function


Hello folks! welcome back to a new edition of our tutorial on PHP. In this tutorial guide, we are going to be studying about the PHP mysqli_more_results() Function.

The built-in mysqli_more_results() function is used in verifying whether there are more results from the last executed multi-query.

Syntax

Following below is the syntax to use this function -

mysqli_more_results($con)


Parameter Details

Sr.NoParameter & Description
1

con(Mandatory)

This is an object representing a connection to MySQL Server.


Return Value

This built-in PHP function returns TRUE if there are more result sets (or, errors) and it returns FALSE if there are no more result set.

PHP Version

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

Example1

The following example illustrates the usage of PHP mysqli_more_results() function (in a 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);
?>

Output

When the above code is executed, it will produce the following result -

Name: Kennedy
Age: 27

Name: Paul
Age: 30

Name: Precious
Age: 25

::::::::::::::::::::::::::::::
Name: Justice
Age: 28

Name: Bethel
Age: 27

Name: Stephanie
Age: 24

Example2

In an object oriented style the syntax of this PHP function is $con->more_results(); The following is the example of this function in an 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();
?>

Output

When the above code is executed, it will produce the following result -

Name: Kennedy
Age: 27

Name: Paul
Age: 30

Name: Precious
Age: 25

::::::::::::::::::::::::::::::
Name: Justice
Age: 28

Name: Bethel
Age: 27

Name: Stephanie
Age: 24


Alright guys! This is where we are going to be rounding up for this tutorial post. In our next tutorial, we are going to be discussing about the mysqli_multi_query() Function.

Do feel free to ask your questions where necessary and we will attend to them as soon as possible. If this tutorial was helpful to you, you can use the share button to share this tutorial.

Do follow us on our various social media handles available and also subscribe to our newsletter to get our tutorial posts delivered directly to your emails.

Thanks for reading and bye for now.