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_info() Function.
The PHP mysqli_info() function is used to get information about the query that was executed by the last MYSQLi function call. This PHP function supports queries that are only in the following format below -
The PHP mysqli_info() function is used to get information about the query that was executed by the last MYSQLi function call. This PHP function supports queries that are only in the following format below -
- INSERT INTO...SELECT....
- INSERT INTO...VALUES (...),(...),(...).
- LOAD DATA INFILE....
- ALTER TABLE....
- UPDATE....
Syntax
Following below is the syntax to use this function -
mysqli_info($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 a string value representing the description/info of latest query executed. If the latest query executed is not one of the supported ones, then this function returns an empty string.
PHP Version
This PHP function was first introduced in PHP version 5 and it works in all the later versions.
Example1
The following example below illustrates the usage of the PHP mysqli_info() function (in a procedural style) -
<?php //Creating a connection $con = mysqli_connect("localhost", "root", "password", "mydb"); //Query to insert a record into the employee table mysqli_query($con, "INSERT INTO employee VALUES ('Kennedy', 'Nkpara', 27, 'M', 15000, 101), ('Precious', 'Amah', 25, 'F', 2256, 102)"); //Query Info $error = mysqli_info($con); print("Query Info: ".$error); //Closing the connection mysqli_close($con); ?>
Output
When the above code is executed, it will produce the following result -
Query Info: Records: 2 Duplicates: 0 Warnings: 0
Example2
In an object oriented style the syntax of this PHP function is $con->info. The following is the example of this PHP function in object oriented style -
<?php //Creating a connection $con = new mysqli("localhost", "root", "password", "mydb"); //Query to retrieve all the rows of employee table $con -> query("INSERT INTO employee VALUES ('Kennedy', 'Nkpara', 27, 'M', 15000, 101), ('Precious', 'Amah', 25, 'F', 2256, 102)"); //Query Info $info = $con ->info; print("Query Info: ".$info); //Closing the connection $con -> close(); ?>
Output
When the above code is executed, it will produce the following result -
Query Info: Records: 2 Duplicates: 0 Warnings: 0
Example3
Following is another example of the PHP mysqli_info() function -
<?php //Creating a connection $con = mysqli_connect("localhost", "root", "password", "mydb"); //ALTER TABLE Query mysqli_query($con, "ALTER TABLE table_name DROP COLUMN CONTACT"); print("Info: ".mysqli_info($con)."\n"); //UPDATE Query mysqli_query($con, "UPDATE employee set INCOME=INCOME+5000"); print("Info: ".mysqli_info($con)."\n"); //INSERT Query mysqli_query($con, "INSERT INTO employee (FIRST_NAME, AGE) VALUES (Paul, 30), (Justice, 28)"); print("Info: ".mysqli_info($con)."\n"); //INSERT Query using SELECT mysqli_query($con, "INSERT into employee(FIRST_NAME, LAST_NAME, AGE) select 'Stephen', 'Harcourt', 29"); print("Info: ".mysqli_info($con)."\n"); //Closing the connection mysqli_close($con); ?>
Output
When the above code is executed, it will produce the following result -
Info: Info: Rows matched: 3 Changed: 3 Warnings: 0 Info: Rows matched: 3 Changed: 3 Warnings: 0 Info: Records: 1 Duplicates: 0 Warnings: 0
Example4
Try the following example below -
<?php $connection_mysql = mysqli_connect("localhost","root","password","mydb"); if (mysqli_connect_errno($connection_mysql)){ echo "Failed to connect to MySQL: " . mysqli_connect_error(); } $sql1 = "CREATE TABLE NewTable SELECT * FROM(employee)"; mysqli_query($connection_mysql,$sql1); echo mysqli_info($connection_mysql); mysqli_close($connection_mysql); ?>
Output
When the above code is executed, it will produce the following result -
Records: 7 Duplicates: 0 Warnings: 0
Alright guys! This is where we are rounding up for this tutorial post. In our next tutorial, we will discuss about the PHP mysqli_init() 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.