MySQLi Tutorial MySQLi References

mysqli $server_info Property



The mysqli::$server_info / mysqli::get_server_info() / mysqli_get_server_info() function returns a string representing the version of the MySQL server that the MySQLi extension is connected to.

Syntax

//Object-oriented style
$mysqli->server_info;
public mysqli::get_server_info();

//Procedural style
mysqli_get_server_info(mysql)

Parameters

mysql Required. For procedural style only: Specify a mysqli object returned by mysqli_connect() or mysqli_init().

Return Value

Returns a character string representing the server version.

Example: Object-oriented style

The example below shows the usage of mysqli::$server_info property.

<?php
//establishing connection to the database
$mysqli = new mysqli("localhost", "user", "password", "database");
if ($mysqli->connect_errno) {
  echo "Connection error: ". $mysqli->connect_error;
  exit();
}

//printing the server version
printf("Server version: %s\n", $mysqli->server_info);

//closing the connection
$mysqli->close();
?>

The output of the above code will be similar to:

Server version: 4.1.2-alpha-debug

Example: Procedural style

The example below shows the usage of mysqli_get_server_info() function.

<?php
//establishing connection to the database
$mysqli = mysqli_connect("localhost", "user", "password", "database");
if (mysqli_connect_errno()) {
  echo "Connection error: ". mysqli_connect_error();
  exit();
}

//printing the server version
printf("Server version: %s\n", mysqli_get_server_info($mysqli));

//closing the connection
mysqli_close($mysqli);
?>

The output of the above code will be similar to:

Server version: 4.1.2-alpha-debug

❮ MySQLi Functions Reference