PHP mysqli_stat() 函式



定義和用法

mysqli_stat() 函式檢索並返回當前伺服器的資訊/狀態。此資訊包括有關伺服器的詳細資訊,例如執行緒數、開啟的表數、正常執行時間等。

語法

mysqli_stat($con)

引數

序號 引數及描述
1

con(必填)

這是一個表示與 MySQL 伺服器連線的物件。

返回值

PHP mysqli_stat() 函式返回一個字串值,表示當前 MySQL 伺服器的狀態。如果發生錯誤,此函式返回布林值 false

PHP 版本

此函式首次在 PHP 5 版本中引入,並在所有後續版本中有效。

示例

以下示例演示了 mysqli_stat() 函式(在過程式風格中)的使用:-

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

這將產生以下結果:-

Status: Uptime: 130131  Threads: 2  Questions: 350  Slow queries: 0  Opens: 172  Flush tables: 1  Open tables: 145  Queries per second avg: 0.002

示例

在面向物件風格中,此函式的語法為 $con->stat();。以下是此函式在面向物件風格中的示例:-

<?php
   //Creating a connection
   $con = new mysqli("localhost", "root", "password", "mydb");

   //Status
   $stat = $con->stat();
   print("Status: ".$stat);

   //Closing the connection
   $con -> close();
?>

這將產生以下結果:-

Status: Uptime: 131057  Threads: 2  Questions: 354  Slow queries: 0  Opens: 172  Flush tables: 1  Open tables: 145  Queries per second avg: 0.002

示例

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

這將產生以下結果:-

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
php_function_reference.htm
廣告