w3resource

PHP mysqli: info() function

mysqli_info function / mysqli::$info

The mysqli_info function / mysqli::$info — retrieves information about the most recently executed query.

This function works with the following query types:

Possible mysqli_info return values
Query Return values
INSERT INTO...SELECT... Records: 10 Duplicates: 0 Warnings: 0
INSERT INTO...VALUES (...),(...),(...) Records: 5 Duplicates: 0 Warnings: 0
LOAD DATA INFILE ... Records: 1 Deleted: 0 Skipped: 0 Warnings: 0
ALTER TABLE ... Records: 4 Duplicates: 0 Warnings: 0
UPDATE ... Rows matched: 50 Changed: 50 Warnings: 0

mysqli::$info -- mysqli_info — Retrieves information about the most recently executed query

Syntax:

Object oriented style

string $mysqli->info;

Procedural style

string mysqli_info ( mysqli $link )

Parameter:

Name Description Required/Optional
connection A link identifier returned by mysqli_connect() or mysqli_init() Required for procedural style only and Optional for Object oriented style

Usage: Procedural style

mysqli_info(connection);

Parameter:

Name Description Required/Optional
connection Specifies the MySQL connection to use. Required

Return value:

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

Version: PHP 5, PHP 7

Example of object oriented style:

<?php
$mysqli = new mysqli("localhost", "user1", "datasoft123", "hr");

/* check connection */
if (mysqli_connect_errno()) {
    printf("Connect failed: %s\n", mysqli_connect_error());
    exit();
}

$mysqli->query("CREATE TEMPORARY TABLE t1 LIKE City");

/* INSERT INTO .. SELECT */
$mysqli->query("INSERT INTO t1 SELECT * FROM City ORDER BY ID LIMIT 150");
printf("%s\n", $mysqli->info);

/* close connection */
$mysqli->close();
?>

Example of procedural style:

<?php
$link = mysqli_connect("localhost", "user1", "datasoft123", "hr");

/* check connection */
if (mysqli_connect_errno()) {
    printf("Connect failed: %s\n", mysqli_connect_error());
    exit();
}

mysqli_query($link, "CREATE TEMPORARY TABLE t1 LIKE City");

/* INSERT INTO .. SELECT */
mysqli_query($link, "INSERT INTO t1 SELECT * FROM City ORDER BY ID LIMIT 150");
printf("%s\n", mysqli_info($link));

/* close connection */
mysqli_close($link);
?>

Output:

Records: 150  Duplicates: 0  Warnings: 0

Example:

<?php
$con=mysqli_connect("localhost","user1","datasoft123","hr");
// Check connection
if (mysqli_connect_errno())
  {
  echo "Failed to connect to MySQL: " . mysqli_connect_error();
  }

// Perform queries
$sql1="CREATE TABLE orders LIKE employees";
mysqli_query($con,$sql1);
$sql2="INSERT INTO orders SELECT * FROM oldorders ORDER BY Last_Name LIMIT 10";
mysqli_query($con,$sql2);

// Print info about most recently executed query
echo mysqli_info($con); 

mysqli_close($con);
?>

See also

PHP Function Reference

Previous: get_warnings
Next: init



Become a Patron!

Follow us on Facebook and Twitter for latest update.

It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.

https://www.w3resource.com/php/function-reference/mysqli_info.php