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_info()

    PHP MySQLi Reference Manual

The mysqli_get_server_info() function returns the version number of the MySQL server

Definition and usage

mysqli_get_server_info()The function is used to obtain information about the MySQL server (version) connected to the established connection.

Syntax

mysqli_get_server_info([$con]);

Parameter

Serial numberParameters and descriptions
1

con(Required)

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

Return value

The PHP mysqli_get_server_info() function returns a string that represents the version of the MySQL server connected to by the mysqli extension.

PHP version

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

Online Example

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

Online Example

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

Online Example

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

Online Example

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

PHP MySQLi Reference Manual