info
In this article, we will focus on the mysqli_info() function in PHP, which is used to return information about the most recently executed query. We will provide
This article covers the mysqli_info() function in PHP, which returns a human-readable string describing what the most recently executed query did. You will learn what the function returns, which statements produce output, how to call it in both the procedural and object-oriented MySQLi styles, and how it differs from related functions such as mysqli_affected_rows().
What mysqli_info() returns
mysqli_info() is a built-in PHP function that returns a formatted status string for the last query run on a given connection. The string is the same text the MySQL server reports for the statement — it is meant for humans, not for parsing.
It only produces a string for statements that modify or load multiple rows. For other queries (a plain SELECT, a CREATE TABLE, etc.) it returns an empty string or NULL. The statements that produce a string are:
| Statement | Example output string |
|---|---|
INSERT INTO ... SELECT ... | Records: 3 Duplicates: 0 Warnings: 0 |
INSERT INTO ... VALUES (...),(...) | Records: 2 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 |
Because the format is not stable across statement types or MySQL versions, treat the string as a display value. To read individual numbers programmatically, use the dedicated functions instead — see mysqli_affected_rows() and mysqli_warning_count().
Syntax
mysqli_info() takes the link returned by mysqli_connect():
// Procedural style
string mysqli_info(mysqli $link)
// Object-oriented style
string $mysqli->infoIn the object-oriented API, info is a property, not a method — note there are no parentheses.
How to use mysqli_info()
Call mysqli_info() on a valid MySQLi connection right after running a query with mysqli_query(). Run the status check before issuing the next query, since each query overwrites the previous status.
<?php
$mysqli = mysqli_connect("localhost", "username", "password", "database");
if (!$mysqli) {
die("Connection failed: " . mysqli_connect_error());
}
// A multi-row INSERT produces a status string
$sql = "INSERT INTO users (name) VALUES ('Ann'), ('Bob'), ('Cara')";
if (mysqli_query($mysqli, $sql)) {
echo mysqli_info($mysqli);
} else {
echo "Query failed: " . mysqli_error($mysqli);
}
mysqli_close($mysqli);
?>For the three-row insert above, the script prints:
Records: 3 Duplicates: 0 Warnings: 0Here Records is the number of rows the statement processed, Duplicates counts rows that collided with a unique key, and Warnings reports non-fatal issues raised during execution.
Object-oriented style
The same logic using the object-oriented MySQLi API reads the info property:
<?php
$mysqli = new mysqli("localhost", "username", "password", "database");
if ($mysqli->connect_errno) {
die("Connection failed: " . $mysqli->connect_error);
}
$mysqli->query("INSERT INTO users (name) VALUES ('Ann'), ('Bob'), ('Cara')");
echo $mysqli->info; // Records: 3 Duplicates: 0 Warnings: 0
$mysqli->close();
?>mysqli_info() vs mysqli_affected_rows()
These are easy to confuse:
mysqli_info()returns a formatted string for display and works only for the statement types listed above.- mysqli_affected_rows() returns an integer count of rows changed by
INSERT,UPDATE,DELETE, orREPLACE— use this when you need a number in your code.
If you need the count, never parse the mysqli_info() string; call mysqli_affected_rows() directly.
Common gotchas
- A plain
SELECTreturns nothing.mysqli_info()is empty forSELECT; to count returned rows usemysqli_num_rows()on the result set. - The status resets on the next query. Read
mysqli_info()immediately after the query you care about. - Don't parse the string. Its wording changes between statement types and server versions; use the dedicated count/warning functions for logic.
Conclusion
mysqli_info() is a quick way to get a human-readable summary of what the last query did — how many records were processed, how many were duplicates, and how many warnings occurred. Use it for logging and debugging, and reach for mysqli_affected_rows() or mysqli_warning_count() when your code needs the numbers themselves. For more on running queries, see the PHP MySQLi overview.