PHP mysqli: stat() function
mysqli_stat() function / mysqli::stat
The mysqli_stat() function / mysqli::stat returns the current system status.
Syntax:
Object oriented style
string mysqli::stat ( void )
Procedural style
string mysqli_stat ( mysqli $link )
Parameter:
Name | Description | Required/Optional | |
---|---|---|---|
link | A link identifier returned by mysqli_connect() or mysqli_init() | Required for procedural style only and Optional for Object oriented style |
Return value:
A string describing the server status. FALSE if an error occurred.
Version: PHP 5, PHP 7
Example of object oriented style:
<?php
$mysqli = new mysqli("localhost", "user1", "datasoft123", "hr");
/* check connection */
if (mysqli_connect_errno()) {
printf("Connect failed: %s\n", mysqli_connect_error());
exit();
}
printf ("System status: %s\n", $mysqli->stat());
$mysqli->close();
?>
Example of the Procedural style
<?php
$link = mysqli_connect("localhost", "user1", "datasoft123", "hr");
/* check connection */
if (mysqli_connect_errno()) {
printf("Connect failed: %s\n", mysqli_connect_error());
exit();
}
printf("System status: %s\n", mysqli_stat($link));
mysqli_close($link);
?>
Output:
System status: Uptime: 15092 Threads: 2 Questions: 102 Slow queries: 0 Opens: 16 Flush tables: 1 Open tables: 0 Queries per second avg: 0.6 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:
<php
$con=mysqli_connect("localhost","user1","datasoft123","hr");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
echo "System status: ". mysqli_stat($con);
mysqli_close($con);
?>
Output:
System status: Uptime: 17266 Threads: 1 Questions: 142 Slow queries: 0 Opens: 25 Flush tables: 1 Open tables: 0 Queries per second avg: 0.8
See also
It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.
https://www.w3resource.com/php/function-reference/mysqli_stat.php
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics