PHP mysqli_stat() Function
Definition and Usage
The mysqli_stat() function retrieves and returns the information/status of the current Server. This information includes details about the server such as, number of threads, number of open tables, up time etc.
Syntax
mysqli_stat($con)
Parameters
| Sr.No | Parameter & Description |
|---|---|
| 1 |
con(Mandatory) This is an object representing a connection to MySQL Server. |
Return Values
PHP mysqli_stat() function returns an string value representing the status of the current MySQL server. Incase of an error this function returns the boolean value false.
PHP Version
This function was first introduced in PHP Version 5 and works works in all the later versions.
Example
Following example demonstrates the usage of the mysqli_stat() function (in procedural style) −
<?php
//Creating a connection
$con = mysqli_connect("localhost", "root", "password", "mydb");
//Status
$stat = mysqli_stat($con);
print("Status: ".$stat);
//Closing the connection
mysqli_close($con);
?>
This will produce following result −
Status: Uptime: 130131 Threads: 2 Questions: 350 Slow queries: 0 Opens: 172 Flush tables: 1 Open tables: 145 Queries per second avg: 0.002
Example
In object oriented style the syntax of this function is $con->stat();. Following is the example of this function in object oriented style −
<?php
//Creating a connection
$con = new mysqli("localhost", "root", "password", "mydb");
//Status
$stat = $con->stat();
print("Status: ".$stat);
//Closing the connection
$con -> close();
?>
This will produce following result −
Status: Uptime: 131057 Threads: 2 Questions: 354 Slow queries: 0 Opens: 172 Flush tables: 1 Open tables: 145 Queries per second avg: 0.002
Example
<?php
$connection_mysql = mysqli_connect("localhost", "root", "password", "mydb");
if (mysqli_connect_errno($connection_mysql)){
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
echo "System status: ". mysqli_stat($connection_mysql);
mysqli_close($connection_mysql);
?>
This will produce following result −
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