English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

Basic PHP Tutorial

Advanced PHP Tutorial

PHP & MySQL

PHP Reference Manual

Usage and Examples of PHP mysqli_info() Function

    PHP MySQLi Reference Manual

The mysqli_info() function returns information about the latest executed SQL statement

Definition and Usage

mysqli_info()The function returns information about the query executed by the latest MySQLi function call. This function supports queries in the following format only:

  • INSERT INTO...SELECT....

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

  • LOAD DATA INFILE ...

  • ALTER TABLE ...

  • UPDATE ...

Syntax

mysqli_info($con)

Parameter

Serial numberParameters and descriptions
1

con (required)

This is an object representing the connection with the MySQL Server.

Return value

The PHP mysqli_info() function returns a string value that represents the description of the latest executed query/Information. If the latest query executed is not a supported query, this function returns an empty string.

PHP version

This function was originally in PHP version5introduced and can be used in all higher versions.

Online Example

The following example demonstratesmysqli_info()Function usage (procedural style)-

<?php
   //Establish connection
   $con = mysqli_connect("localhost", "root", "password", "mydb");
   //Query and insert records into the employee table
   mysqli_query($con, "INSERT INTO employee VALUES ('Sarmista', 'Sharma', 28, 'F', 15000,  101), ('Sheldon', 'Cooper', 25, 'M', 2256,  102);
   //Query information
   $error = mysqli_info($con);
   print("Query information: ".$error);
   //Close Connection
   mysqli_close($con);
?>

Output Result

Query information: Records: 2  Duplicates: 0  Warnings: 0

Online Example

In the object-oriented style, the syntax of this function is$ con-> info. The following is an example of this function in object-oriented style-

<?php
   //Establish connection
   $con = new mysqli("localhost", "root", "password", "mydb");
   //Query to retrieve all the rows of the employee table
   $con -> query("INSERT INTO employee VALUES ('Sarmista', 'Sharma', 28, 'F', 15000,  101), ('Sheldon', 'Cooper', 25, 'M', 2256,  102);
   //Query information
   $info = $con -> info;
   print("Query information: ".$info);
   //Close Connection
   $con -> close();
?>

Output Result

Query information: Records: 2  Duplicates: 0  Warnings: 0

Online Example

The following ismysqli_info()Another example of the function-

<?php
   //Establish 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 Using SELECT Statement
   mysqli_query($con, "INSERT into employee(FIRST_NAME, LAST_NAME, AGE) select 'Manoj', 'Tiwari', 45");
   print("Info: " . mysqli_info($con) . "\n");
   //Close Connection
   mysqli_close($con);
?>

Output 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

Online Example

Return information of the latest executed query:

<?php
   $connection_mysql = mysqli_connect("localhost", "root", "password", "mydb");
   
   if (mysqli_connect_errno($connection_mysql)){
      echo "Connection to MySql failed: " . 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 Result

Records: 7  Duplicates: 0  Warnings: 0

PHP MySQLi Reference Manual