English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
The mysqli_get_server_info() function returns the version number of the MySQL server
mysqli_get_server_info()The function is used to obtain information about the MySQL server (version) connected to the established connection.
mysqli_get_server_info([$con]);
Serial number | Parameters and descriptions |
---|---|
1 | con(Required) This is an object representing the connection to the MySQL Server. |
The PHP mysqli_get_server_info() function returns a string that represents the version of the MySQL server connected to by the mysqli extension.
This function was originally introduced in PHP version5introduced and can be used in all higher versions.
The following examples demonstratemysqli_get_server_info()Usage of the function (procedural style)-
<?php //Establish Connection $con = mysqli_connect("localhost", "root", "password", "mydb"); //MySQL Server Version $version = mysqli_get_server_info($con); print("MySQL Server Version Number: ".$version); //Close Connection mysqli_close($con); ?>
Output Result
MySQL Server Version Number: 5.7.12-log
In object-oriented style, the syntax of this function is$con-> client_info.Here is an example of this function in object-oriented style-
<?php //Establish Connection $con = new mysqli("localhost", "root", "password", "mydb"); //MySQL Server Version $version = $con-> server_info; print("MySQL Server Version Number: ".$version); //Close Connection $con -> close(); ?>
Output Result
MySQL Server Version Number: 5.7.12-log
<?php //Establish Connection $con = @mysqli_connect("localhost", "root", "password", "mydb"); $code = mysqli_connect_errno(); if ($code){ print("Connection failed: ".$code); } else { print("Connection established successfully"."\n"); $info = mysqli_get_server_info($con); print("MySQL Server Version Number: ".$info); } ?>
Output Result
Connection established successfully MySQL Server Version Number: 5.7.12-log
Return MySQL server version:
<?php $connection_mysql = mysqli_connect("localhost", "user_name", "password", "database_name"); if (mysqli_connect_errno($connection_mysql)){ print("Connection to MySQL failed: ".mysqli_connect_error()); } print(mysqli_get_server_info($connection_mysql)); mysqli_close($connection_mysql); ?>
Output Result
5.7.12-log