The mysqli::stat() function is used to obtain statistics about the current database connection. It returns a string containing the connection status.
The following are the usage and examples of the mysqli::stat() function:
usage:
string mysqli::stat ( void )
Example:
// 创建数据库连接$mysqli = new mysqli("localhost", "username", "password", "database"); // 检查连接是否成功if ($mysqli->connect_errno) { echo "连接失败:" . $mysqli->connect_error; exit(); } // 获取数据库连接的统计信息$stat = $mysqli->stat(); // 打印统计信息echo "数据库连接统计信息:" . $stat; // 关闭数据库连接$mysqli->close();
In the example above, we first create a mysqli object, using the provided hostname, username, password, and database name to connect. Then we check if the connection is successful, if the connection fails, output an error message and exit the program.
Next, we call the mysqli::stat() function to get the statistics of the database connection and store it in the variable $stat.
Finally, we print out the statistics for the database connection.
Note that in order to use the mysqli::stat() function, you need to install and enable the MySQLi extension.