MySQLi
在线手册:中文 英文
PHP手册

mysqli::stat

mysqli_stat

(PHP 5)

mysqli::stat -- mysqli_statGets the current system status

说明

面向对象风格

string mysqli::stat ( void )

过程化风格

string mysqli_stat ( mysqli $link )

mysqli_stat() returns a string containing information similar to that provided by the 'mysqladmin status' command. This includes uptime in seconds and the number of running threads, questions, reloads, and open tables.

参数

link

仅以过程化样式:由 mysqli_connect()mysqli_init() 返回的链接标识。

返回值

A string describing the server status. FALSE if an error occurred.

范例

Example #1 mysqli::stat() example

面向对象风格

<?php
$mysqli 
= new mysqli("localhost""my_user""my_password""world");

/* check connection */
if (mysqli_connect_errno()) {
    
printf("Connect failed: %s\n"mysqli_connect_error());
    exit();
}

printf ("System status: %s\n"$mysqli->stat());

$mysqli->close();
?>

过程化风格

<?php
$link 
mysqli_connect("localhost""my_user""my_password""world");

/* 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);
?>

以上例程会输出:

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

参见


MySQLi
在线手册:中文 英文
PHP手册
PHP手册 - N: Gets the current system status

用户评论:

nycdiesl at gmail dot com (01-May-2009 02:10)

PHP 5.2.9
A small example

<?php
$dbh
= new mysqli('host', 'user', 'password', 'database');
if (
$dbh->connect_error) {
   die(
"Connection Error ({$dbh->connect_errno}) {$dbh->connect_error}");
}

if ((
$stats = $dbh->stat()) !== FALSE) {
   echo
"Dumping output method stat() ...\n";
   echo
"$stats\n";

  
$statsArray = explode("  ", $stats);
  
print_r($stats);
}
?>

Dumping stats:
Uptime: 1095822  Threads: 5  Questions: 5326101  Slow queries: 0  Opens: 7352  Flush tables: 1  Open tables: 60  Queries per second avg: 4.860
Array
(
    [0] => Uptime: 1095822
    [1] => Threads: 5
    [2] => Questions: 5326101
    [3] => Slow queries: 0
    [4] => Opens: 7352
    [5] => Flush tables: 1
    [6] => Open tables: 60
    [7] => Queries per second avg: 4.860
)

The above code will print out a string and then attempt to create an array by exploding the string using a delimiter of two spaces (eg: "  "). This should give you an array to work with, however, I'm just beginning to use this extension, so feel free to correct any errors discovered :)