PHP | mysqli_more_results() Function
January 24, 2021
Hello folks! welcome back to another edition of our tutorial on PHP. In this tutorial guide, we are going to be discussing about the PHP mysqli_more_results() Function.
The built-in PHP mysqli_more_results() function verifies whether there are more results from the last executed multi-query.
The built-in PHP mysqli_more_results() function verifies 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.No | Parameter & 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 built-in PHP function was first introduced in PHP version 5 and works in all the later versions.
Example1
The following below is an example which demonstrates 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 object oriented style the syntax of this built-in 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 rounding up for this tutorial post. In our next tutorial, we will discuss about the PHP 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.
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.