mysql_stat() function for PHP

What is mysql_stat() function in PHP?
How does mysql_stat() works?

Explanation

Mysql function mysql_stat() returns the current system status of the MySQL server.
Syntax
string mysql_stat ( [ resource link_identifier ])

Returns status on success, or NULL on failure.
mysql_stat() returns current server status. mysql_stat() returns status for uptime, threads, open tables, flush tables and queries per second.
Example:

<?php
$link = mysql_pconnect("mysql_host", "mysql_user", "mysql_password")
or die ("Could not connect");
$status = explode(' ', mysql_stat($link));
print_r($status);
?>

RESULT:
Array
(
[0] => Uptime: 99410
[1] => Threads: 2
[2] => Questions: 1321299
[3] => Slow queries: 0
[4] => Opens: 26
[5] => Flush tables: 1
[6] => Open tables: 17
[7] => Queries per second avg: 245.595
)
For a complete list of other status variables you have to use the SHOW STATUS SQL command.
Example

<?php
$link = mysql_pconnect("mysql_host", "mysql_user", "mysql_password")
or die ("Could not connect");
$result = mysql_query('SHOW STATUS', $link);
while ($row = mysql_fetch_assoc($result)) {
echo $row['Variable_name'] . ' = ' . $row['Value'] . "<br>";
}
?>

RESULT:
Aborted_clients = 0
Aborted_connects = 0
Binlog_cache_disk_use = 0
Binlog_cache_use = 0
Bytes_received = 144
Bytes_sent = 15855
Com_admin_commands = 0
Com_alter_db = 0
Com_alter_table = 0
Com_analyze = 0
Com_backup_table = 0
Com_begin = 0
Com_change_db = 0
Com_change_master = 0
Com_check = 0
Com_checksum = 0
Com_commit = 0
Com_create_db = 0
Com_create_function = 0
Com_create_index = 0
Com_create_table = 0
.....
.....etc

PHP Topics


Ask Questions

Ask Question