PHP mysqli_info() Function

Beginner
5 min read
Updated: Nov 2026
3 examples
MySQLi

Definition

In PHP, mysqli_info() returns a short summary string about the last query when MySQL provides one, such as how many rows were matched or inserted.

Only certain statement shapes fill the info string: multi-row INSERT, INSERT...SELECT, LOAD DATA, UPDATE and ALTER TABLE style work. Other queries usually yield null or an empty string.

Syntax

Call mysqli_info() with the values you need. Start with this line.

PHP
$summary = mysqli_info($mysqli);
CallWhat it does
mysqli_info($mysqli)Returns a summary string or null/empty when unsupported.
echo mysqli_info($mysqli)Prints text like "Rows matched: 3 Changed: 1 Warnings: 0".
$s = mysqli_info($mysqli) ?? "n/a";Uses null coalescing when no info string exists.

Think of mysqli_info() as optional extra detail after INSERT, UPDATE or LOAD DATA. For a single AUTO_INCREMENT id use mysqli_insert_id(). For row counts on SELECT use mysqli_num_rows() on a stored result.

Library declarations
PHP
mysqli_info(mysqli $mysql): ?string

Parameters

ParameterDescription
mysqlRequired. The mysqli connection that ran the last query.

Return Value

Return ValueDescription
?stringA summary string for supported query types, or null/empty when MySQL did not provide info.

PHP Examples

Example 1 — Read Info After a Multi-Row Insert

After inserting several rows, print the info summary. Output is a typical sample.

PHP
<?php
$mysqli = mysqli_connect("localhost", "demo_user", "demo_pass", "app_db");

mysqli_query(
    $mysqli,
    "INSERT INTO tags (name) VALUES ('php'), ('mysql'), ('html')"
);

echo mysqli_info($mysqli), PHP_EOL;

mysqli_close($mysqli);

How It Works

  1. A multi-value INSERT is one of the statement types that fills info.
  2. mysqli_info() returns the server summary string.
  3. The sample shows three records and no duplicates.
  4. Close the connection when done.

Example 2 — Info After UPDATE

UPDATE statements often report matched and changed counts.

PHP
<?php
$mysqli = mysqli_connect("localhost", "demo_user", "demo_pass", "app_db");

mysqli_query($mysqli, "UPDATE products SET active = 1 WHERE active = 1");

$info = mysqli_info($mysqli);
echo $info !== null && $info !== "" ? $info : "(no info)", PHP_EOL;

mysqli_close($mysqli);

How It Works

  1. The UPDATE matches four rows but changes none in this sample.
  2. mysqli_info() reports matched vs changed separately.
  3. mysqli_affected_rows() alone would not show both numbers this clearly.
  4. Always handle null or empty when the statement type has no info.

Example 3 — SELECT Usually Has No Info String

Show that a normal SELECT leaves info empty.

PHP
<?php
$mysqli = mysqli_connect("localhost", "demo_user", "demo_pass", "app_db");

mysqli_query($mysqli, "SELECT id FROM products LIMIT 5");
$info = mysqli_info($mysqli);

var_dump($info);

mysqli_close($mysqli);

How It Works

  1. SELECT is not one of the info-producing formats.
  2. mysqli_info() returns null in this sample.
  3. Use mysqli_num_rows() on the result for SELECT counts.
  4. Treat missing info as normal, not as an error.

Frequently Asked Questions

A summary string for certain INSERT, UPDATE, LOAD DATA and ALTER statements, or null/empty otherwise.
Typical cases include multi-row INSERT, INSERT...SELECT, LOAD DATA, UPDATE and some ALTER TABLE statements.
No. affected_rows is a number for logic. info is optional human-readable text with more detail for some statements.
SELECT is not a supported info format. Use the result object and mysqli_num_rows() instead.
Prefer dedicated functions for decisions. Parsing info is brittle because the text format is meant for people.

Next: mysqli_init()

mysqli_init() creates a new mysqli object that is not connected yet, so you can set option.

mysqli_init() tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

8 people found this page helpful