English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
The mysqli_get_server_version() function returns the MySQL server version as an integer.
mysqli_get_server_version()The function returns the version number of the currently connected MySQL server.
mysqli_get_server_version($con);
Serial number | Parameters and descriptions |
---|---|
1 | con(mandatory) This is an object representing the connection with the MySQL Server. |
The PHP mysqli_get_server_version() function returns an integer value that represents the version of the MySQL server that has been connected.
This function was initially introduced in PHP version5introduced and can be used in all higher versions.
The following examples demonstratemysqli_get_server_version()The usage of the function (procedural style)-
<?php //Establish Connection $con = mysqli_connect("localhost", "root", "password", "mydb"); //MySQL Server Version Number $version = mysqli_get_server_version($con); print("MySQL Server Version Number: ".$version); //Close Connection mysqli_close($con); ?>
Output Result
MySQL Server Version Number: 50712
In the object-oriented style, the syntax of this function is$ con-> server_version.Here is an example of this function in an object-oriented style-
<?php //Establish Connection $con = new mysqli("localhost", "root", "password", "mydb"); //MySQL Server Version Number $version = $con-> server_version; print("MySQL Server Version Number: ".$version); //Close Connection $con -> close(); ?>
Output Result
MySQL Server Version Number: 50712
<?php //Establish Connection $con = @mysqli_connect("localhost", "root", "password", "mydb"); $code = mysqli_connect_errno(); if($code){ print("Connection failed: ".$code); } print("Connection established successfully. "); $info = mysqli_get_server_version($con); print("MySQL Server Version Number: ".$info); } ?>
Output Result
Connection established successfully MySQL Server Version Number: 50712
Return the MySQL server version as an integer:
<?php $connection_mysql = mysqli_connect("localhost", "root", "password", "mydb"); if (mysqli_connect_errno($connection_mysql)){ print("Connection to MySQL failed: ".mysqli_connect_error()); } print(mysqli_get_server_version($connection_mysql)); mysqli_close($connection_mysql); ?>
Output Result
50712