PHP Function Reference

PHP mysqli $server_version Property



The PHP mysqli::$server_version / mysqli_get_server_version() function returns the version of the MySQL server as an integer.

Syntax

//Object-oriented style
$mysqli->server_version;

//Procedural style
mysqli_get_server_version(mysql)

Parameters

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

Return Value

Returns an integer representing the server version. The form of this version number is main_version * 10000 + minor_version * 100 + sub_version (i.e. version 4.1.0 is 40100).

Example: Object-oriented style

The example below shows the usage of mysqli::$server_version 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_version);

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

The output of the above code will be similar to:

Server version: 40102

Example: Procedural style

The example below shows the usage of mysqli_get_server_version() 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_version($mysqli));

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

The output of the above code will be similar to:

Server version: 40102

❮ PHP MySQLi Reference