MySQLi Tutorial MySQLi References

mysqli $info Property



The mysqli::$info / mysqli_get_info() function is used to retrieve information about the most recently executed query. The nature of this string is provided below:

Possible mysqli_info return values

Query typeExample result string
INSERT INTO...SELECT...Records: 100 Duplicates: 0 Warnings: 0
INSERT INTO...VALUES (...),(...),(...)Records: 3 Duplicates: 0 Warnings: 0
LOAD DATA INFILE ...Records: 1 Deleted: 0 Skipped: 0 Warnings: 0
ALTER TABLE ...Records: 3 Duplicates: 0 Warnings: 0
UPDATE ...Rows matched: 40 Changed: 40 Warnings: 0

Note: Queries which do not fall into one of the preceding formats are not supported. In these situations, mysqli_info() will return an empty string.

Syntax

//Object-oriented style
$mysqli->info;

//Procedural style
mysqli_get_info(mysql)

Parameters

mysql Required. For procedural style only: Specify a mysqli object returned by mysqli_connect() or mysqli_init().

Return Value

Returns a character string representing additional information about the most recently executed query.

Example: Object-oriented style

The example below shows the usage of mysqli::$info property.

<?php
//establishing connection to the database
$mysqli = new mysqli("localhost", "user", "password", "database");
if ($mysqli->connect_errno) {
  echo "Connection error: ". $mysqli->connect_error;
  exit();
}

//creating a temporary table
$mysqli->query("CREATE TEMPORARY TABLE t1 LIKE City");

//using INSERT INTO ... SELECT statement
$mysqli->query("INSERT INTO t1 SELECT * FROM City ORDER BY ID LIMIT 150");

//retrieving information about the most recently executed query
printf("%s\n", $mysqli->info);

//closing the connection
$mysqli->close();
?>

The output of the above code will be similar to:

Records: 150  Duplicates: 0  Warnings: 0

Example: Procedural style

The example below shows the usage of mysqli_get_info() function.

<?php
//establishing connection to the database
$mysqli = mysqli_connect("localhost", "user", "password", "database");
if (mysqli_connect_errno()) {
  echo "Connection error: ". mysqli_connect_error();
  exit();
}

//creating a temporary table
mysqli_query($mysqli, "CREATE TEMPORARY TABLE t1 LIKE City");

//using INSERT INTO ... SELECT statement
mysqli_query($mysqli, "INSERT INTO t1 SELECT * FROM City ORDER BY ID LIMIT 150");

//retrieving information about the most recently executed query
printf("%s\n", mysqli_info($mysqli));

//closing the connection
mysqli_close($mysqli);
?>

The output of the above code will be similar to:

Records: 150  Duplicates: 0  Warnings: 0

❮ MySQLi Functions Reference