PHP mysqli_stat() Function

Beginner
5 min read
Updated: Nov 2026
3 examples
MySQLi

Definition

In PHP, mysqli_stat() returns a single status string from the MySQL server for the current connection.

The text usually includes uptime, threads, questions, and similar server counters in one line. It is a quick diagnostic readout, not a structured array. On failure it returns false.

Syntax

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

PHP
$status = mysqli_stat($mysql);
CallWhat it does
mysqli_stat($link)Returns one status line from the server, or false on failure.
$mysqli->stat()Object-oriented form.
substr((string) mysqli_stat($link), 0, 20)Shows only the beginning of a long status string.

The exact wording depends on the MySQL/MariaDB server version. Treat it as a human-readable snapshot. For structured metrics, look at other server status queries your app is allowed to run.

Library declarations
PHP
mysqli_stat(mysqli $mysql): string|false

Parameters

ParameterDescription
mysqlRequired. Procedural style only: an open mysqli connection.

Return Value

Return ValueDescription
stringA server status summary line.
falseThe status could not be read.

PHP Examples

Example 1 — Print a Sample Status Line

Fixed demo string shaped like a typical mysqli_stat() result.

PHP
<?php
$stat = 'Uptime: 12345  Threads: 2  Questions: 678  Slow queries: 0';
echo $stat, PHP_EOL;

How It Works

  1. Call mysqli_stat($link) on an open connection.
  2. Echo the returned string for a quick look.
  3. This sample mirrors common uptime/threads fields.
  4. Sample output when connected to a demo database will differ in the numbers.

Example 2 — Handle false

Check the return before printing.

PHP
<?php
$stat = false; // stand-in failure
echo $stat === false ? 'stat failed' : $stat, PHP_EOL;

How It Works

  1. A false return means the call failed.
  2. Check connection health with ping/error helpers.
  3. Do not cast false directly to a status string for logs.
  4. Reconnect or fix permissions as needed.

Example 3 — OO Call

Same status string from the method form.

PHP
<?php
class DemoMysqli {
    public function stat() {
        return 'Uptime: 10  Threads: 1  Questions: 3';
    }
}
$mysqli = new DemoMysqli();
echo $mysqli->stat(), PHP_EOL;

How It Works

  1. OO code uses $mysqli->stat().
  2. Procedural code passes the link.
  3. Both return string|false.
  4. Keep this for admin/debug screens, not core business rules.

Frequently Asked Questions

A single status string from MySQL, or false on failure.
No. It varies by server. Use it as a human-readable snapshot.
For quick diagnostics or teaching. Prefer dedicated monitoring for production metrics.
You need a working connection; some environments may still restrict server status details.
stat() is a server status string. get_connection_stats() returns client-side mysqlnd stats as an array when available.

Next: mysqli_stmt_init()

mysqli_stmt_init() creates a blank statement object that you later prepare with mysqli_stm.

mysqli_stmt_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