MySQLi Tutorial MySQLi References

mysqli stat() Method



The mysqli::stat() / mysqli_stat() function is used to get the current system status. This includes uptime in seconds and the number of running threads, questions, reloads, and open tables.

Syntax

//Object-oriented style
public mysqli::stat()

//Procedural style
mysqli_stat(mysql)

Parameters

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

Return Value

Returns a string describing the server status. Returns false if an error occurs.

Example: Object-oriented style

The example below shows the usage of mysqli::stat() method.

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

//getting the current system status
printf ("System status: %s\n", $mysqli->stat());

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

The output of the above code will be similar to:

System status: Uptime: 272  Threads: 1  Questions: 5340  Slow queries: 0
Opens: 13  Flush tables: 1  Open tables: 0  Queries per second avg: 19.632
Memory in use: 8496K  Max memory used: 8560K

Example: Procedural style

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

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

//getting the current system status
printf("System status: %s\n", mysqli_stat($mysqli));

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

The output of the above code will be similar to:

System status: Uptime: 272  Threads: 1  Questions: 5340  Slow queries: 0
Opens: 13  Flush tables: 1  Open tables: 0  Queries per second avg: 19.632
Memory in use: 8496K  Max memory used: 8560K

❮ MySQLi Functions Reference