Current Location: Home> Function Categories> mysqli::$server_info

mysqli::$server_info

(mysqli_get_server_info) Returns the version of MySQL server
Name:mysqli::$server_info
Category:MySQLi
Programming Language:php
One-line Description:Get the version information of the current MySQL server

Function name: mysqli::$server_info()

Applicable version: PHP 5 >= 5.0.0, PHP 7

Function description: The mysqli::$server_info() function is used to obtain the version information of the current MySQL server.

Syntax: string mysqli::$server_info ( void )

Parameters: This function does not accept any parameters.

Return value: Returns a string representing the version information of the current MySQL server.

Example:

<?php // 创建一个新的mysqli对象 $mysqli = new mysqli("localhost", "username", "password", "database"); // 检查连接是否成功 if ($mysqli---> connect_errno) { echo "Connection failed: " . $mysqli->connect_error; exit(); } // Get MySQL server version information $serverInfo = $mysqli->server_info; echo "MySQL server version: " . $serverInfo; // Close the connection $mysqli->close(); ?>

Output: MySQL server version: 5.7.32

In the above example, we first create a mysqli object and connect to the MySQL server with the correct parameters. Then, by accessing the server_info property of the mysqli object, obtain the version information of the MySQL server. Finally, print out the version information.

Note that to ensure the connection is successful, we used the connect_errno property to check for connection errors. In addition, after using the mysqli object, we call the close() method to close the connection to free up the resource.

Similar Functions
Popular Articles