PHP  
downloads | documentation | faq | getting help | mailing lists | reporting bugs | php.net sites | links | my php.net 
search for in the  
<mysql_select_dbmysql_tablename>
view the version of this page
Last updated: Mon, 14 Feb 2005

mysql_stat

(PHP 4 >= 4.3.0, PHP 5)

mysql_stat -- Get current system status

Description

string mysql_stat ( [resource link_identifier] )

mysql_stat() returns the current server status.

Parameters

link_identifier

Link to the MySQL connection.

Return Values

Returns a string with the status for uptime, threads, queries, open tables, flush tables and queries per second. For a complete list of other status variables, you have to use the SHOW STATUS SQL command. If link_identifier is invalid, NULL is returned.

Examples

Example 1. mysql_stat() example

<?php
$link 
= mysql_connect('localhost', 'mysql_user', 'mysql_password');
$status = explode('  ', mysql_stat($link));
print_r($status);
?>

The above example will output something similar to:

Array
(
    [0] => Uptime: 5380
    [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
)

Example 2. Alternative mysql_stat() example

<?php
$link 
= mysql_connect('localhost', 'mysql_user', 'mysql_password');
$result = mysql_query('SHOW VARIABLES', $link);
while (
$row = mysql_fetch_assoc($result)) {
   echo
$row['Variable_name'] . ' = ' . $row['Value'] . "\n";
}
?>

The above example will output something similar to:

back_log = 50
basedir = /usr/local/
bdb_cache_size = 8388600
bdb_log_buffer_size = 32768
bdb_home = /var/db/mysql/
bdb_max_lock = 10000
bdb_logdir = 
bdb_shared_data = OFF
bdb_tmpdir = /var/tmp/
...



add a note add a note User Contributed Notes
mysql_stat
09-Feb-2005 12:16
if you need the complete status as outputted by the "show status" command. Try this function.
<?
function mysql_status($db=NULL) {
if(!
mysql_ping($db))
$db=mysql_connect("localhost","user","password");
$res=mysql_query("show status",$db);
while (list(
$key,$value)=mysql_fetch_array($res))
$sql[$key]=$value;
return
$sql;
}
?>

<mysql_select_dbmysql_tablename>
 Last updated: Mon, 14 Feb 2005
show source | credits | sitemap | contact | advertising | mirror sites 
Copyright © 2001-2005 The PHP Group
All rights reserved.
This unofficial mirror is operated at: http://php.planetmirror.com/
Last updated: Fri Mar 11 09:15:35 2005 EST