Function name: mysqli::get_connection_stats()
Applicable version: PHP 5.4.0 and above
Function description: This function is used to obtain statistical information of the current database connection, including the start time of the connection, the duration of the connection, the number of bytes received and sent, etc.
Syntax: array mysqli::get_connection_stats ( void )
Return value: Returns an associative array containing connection statistics. The key name is the name of the statistics and the key value is the corresponding statistical value. If the statistics are failed, FALSE is returned.
Example:
<?php // 创建数据库连接 $mysqli = new mysqli('localhost', 'username', 'password', 'database'); // 检查连接是否成功 if ($mysqli---> connect_errno) { die('Connection failed: ' . $mysqli->connect_error); } // Execute the query statement $result = $mysqli->query("SELECT * FROM users"); // Get connection statistics $stats = $mysqli->get_connection_stats(); // Output connection start time echo "Connection start time: " . date('Ymd H:i:s', $stats['start_time']) . "In the above example, a database connection is first created and a query statement is executed. Then use the mysqli::get_connection_stats() function to obtain the statistics of the connection and output the connection start time, the connection duration, and the number of bytes received and sent. Finally, the database connection was closed.
Note that to use the mysqli::get_connection_stats() function, you need to create a valid mysqli object and establish a database connection.