• PHP Video Tutorials

PHP mysqli_get_server_info() Function



Definition and Usage

The mysqli_get_server_info() function is used to get the information (version) about the MySQL sever to which a connection is established.

Syntax

mysqli_get_server_info([$con]);

Parameters

Sr.No Parameter & Description
1

con(Mandatory)

This is an object representing a connection to MySQL Server.

Return Values

PHP mysqli_get_server_info() function returns a string representing the version of the MySQL server that the MySQLi extension is connected to.

PHP Version

This function was first introduced in PHP Version 5 and works works in all the later versions.

Example

Following example demonstrates the usage of the mysqli_get_server_info() function (in procedural style) −

<?php
   //Creating a connection
   $con = mysqli_connect("localhost", "root", "password", "mydb");

   //MySQL Server version
   $version = mysqli_get_server_info($con);
   print("Client Library Version Number: ".$version);

   //Closing the connection
   mysqli_close($con);
?>

This will produce following result −

Client Library Version Number: 5.7.12-log

Example

In object oriented style the syntax of this function is $con -> client_info. Following is the example of this function in object oriented style −

<?php
   //Creating a connection
   $con = new mysqli("localhost", "root", "password", "mydb");

   //MySQL Server Version
   $version = $con->server_info;
   print("MySQL Server Version Number: ".$version);

   //Closing the connection
   $con -> close();
?>

This will produce following result −

MySQL Server Version Number: 5.7.12-log

Example

<?php
   //Creating a 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);
   }
?>

This will produce following result −

Connection Established Successfully
MySQL Server Version Number: 5.7.12-log

Example

<?php
   $connection_mysql = mysqli_connect("localhost", "user_name", "password", "database_name");
   
   if (mysqli_connect_errno($connection_mysql)){
      print("Failed to connect to MySQL: ".mysqli_connect_error());
   }
   print(mysqli_get_server_info($connection_mysql));
   
   mysqli_close($connection_mysql);
?>

This will produce following result −

5.7.12-log
php_function_reference.htm
Advertisements