English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

PHP Basic Tutorial

PHP Advanced Tutorial

PHP & MySQL

PHP Reference Manual

Usage and examples of PHP mysqli_get_server_version() function

    PHP MySQLi Reference Manual

The mysqli_get_server_version() function returns the MySQL server version as an integer.

Definition and usage

mysqli_get_server_version()The function returns the version number of the currently connected MySQL server.

Syntax

mysqli_get_server_version($con);

Parameter

Serial numberParameters and descriptions
1

con(mandatory)

This is an object representing the connection with the MySQL Server.

Return value

The PHP mysqli_get_server_version() function returns an integer value that represents the version of the MySQL server that has been connected.

PHP version

This function was initially introduced in PHP version5introduced and can be used in all higher versions.

Online Example

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

Online Example

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

Online Example

<?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

Online Example

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

PHP MySQLi Reference Manual