• PHP Video Tutorials

PHP mysqli_info() Function



Definition and Usage

The mysqli_info() function returns the information about the query executed by the recent MySQLi function call. This function supports queries that are only in the following formats:

  • INSERT INTO...SELECT....

  • INSERT INTO...VALUES (...),(...),(...).

  • LOAD DATA INFILE ....

  • ALTER TABLE ....

  • UPDATE ....

Syntax

mysqli_info($con)

Parameters

Sr.No Parameter & Description
1

con(Mandatory)

This is an object representing a connection to MySQL Server.

Return Values

PHP mysqli_info() function returns an string value representing the description/info of latest query executed. If the latest query executed is not one of the supported ones this function returns an empty string.

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_info() function (in 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 ('Sarmista', 'Sharma', 28, 'F', 15000,  101), ('Sheldon', 'Cooper', 25, 'M', 2256,  102)");

   //Query Info
   $error = mysqli_info($con);
   print("Query Info: ".$error);

   //Closing the connection
   mysqli_close($con);
?>

This will produce following result −

Query Info: Records: 2  Duplicates: 0  Warnings: 0

Example

In object oriented style the syntax of this function is $con ->info. Following is the example of this 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 ('Sarmista', 'Sharma', 28, 'F', 15000,  101), ('Sheldon', 'Cooper', 25, 'M', 2256,  102)");

   //Query Info
   $info = $con ->info;
   print("Query Info: ".$info);

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

This will produce following result −

Query Info: Records: 2  Duplicates: 0  Warnings: 0

Example

Following is another example of the 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 (Archana, 25), (Bhuvan, 29)");
   print("Info: ".mysqli_info($con)."\n");

   //INSERT Query using SELECT
   mysqli_query($con, "INSERT into employee(FIRST_NAME, LAST_NAME, AGE) select 'Manoj', 'Tiwari', 45");
   print("Info: ".mysqli_info($con)."\n");

   //Closing the connection
   mysqli_close($con);
?>

This will produce 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

Example

<?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);
?>

This will produce following result −

Records: 7  Duplicates: 0  Warnings: 0
php_function_reference.htm
Advertisements