English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

PHP Basic Tutorial

PHP Advanced Tutorial

PHP & MySQL

PHP Reference Manual

PHP mysqli_stat() Function Usage and Example

PHP MySQLi Reference Manual

The mysqli_stat() function retrieves the current system status information

Definition and Usage

mysqli_stat()The function retrieves and returns the current server information/Status. This information includes detailed information about the server, such as the number of threads, the number of open tables, the normal operating time, and so on.

Syntax

mysqli_stat($con)

Parameter

Serial NumberParameter and Description
1

con(must)

This is an object representing the connection to the MySQL Server.

Return value

The PHP mysqli_stat() function returns a string value representing the current MySQL server status. If an error occurs, this function will return a boolean valuefalse.

PHP version

This function was originally introduced in PHP version5introduced and can be used in all higher versions.

Online example

The following examples demonstratemysqli_stat()Function usage (procedural style)-

<?php
   //Establish connection
   $con = mysqli_connect("localhost", "root", "password", "mydb");
   //Status
   $stat = mysqli_stat($con);
   print("Status: ". $stat);
   //Close connection
   mysqli_close($con);
?>

Output results

Status: Uptime: 130131  Threads: 2  Questions: 350 Slow queries: 0 Opens: 172  Flush tables: 1  Open tables: 145  Queries per second avg: 0.002

Online example

In object-oriented style, the syntax of this function is$con-> stat();.. Here is an example of this function in object-oriented style-

<?php
   //Establish connection
   $con = new mysqli("localhost", "root", "password", "mydb");
   //Status
   $stat = $con-> stat();
   print("Status: ". $stat);
   //Close connection
   $con -> close();
?>

Output results

Status: Uptime: 131057  Threads: 2  Questions: 354  Slow queries: 0 Opens: 172  Flush tables: 1  Open tables: 145  Queries per second avg: 0.002

Online example

Return the current system status.

<?php
   $connection_mysql = mysqli_connect("localhost", "root", "password", "mydb");
   
   if (mysqli_connect_errno($connection_mysql)){
      echo "Connection to MySQL failed: ". mysqli_connect_error();
   }
   
   echo "System status: ". mysqli_stat($connection_mysql); 
   
   mysqli_close($connection_mysql);
?>

Output results

System status: Uptime: 131468  Threads: 2  Questions: 356  Slow queries: 0 Opens: 172  Flush tables: 1  Open tables: 145  Queries per second avg: 0.002

PHP MySQLi Reference Manual