PHP mysqli_get_server_version() Function

Beginner
5 min read
Updated: Nov 2026
3 examples
MySQLi

Definition

In PHP, mysqli_get_server_version() returns the MySQL server version as an integer for the open connection, such as 80036 for MySQL 8.0.36.

The number packs major, minor and patch as major*10000 + minor*100 + patch. That makes version checks like "is this at least 8.0?" easy without parsing a string.

Syntax

Call mysqli_get_server_version() with the values you need. Start with this line.

PHP
$n = mysqli_get_server_version($mysqli);
CallWhat it does
mysqli_get_server_version($mysqli)Returns an integer such as 80036 for MySQL 8.0.36.
mysqli_get_server_version($mysqli) >= 80000True when the server is MySQL 8.0.0 or newer (same packing rules).
echo mysqli_get_server_version($mysqli)Prints the packed version number.

Prefer this integer for feature gates. Prefer mysqli_get_server_info() when you only want to show the version to a human. Both need a live connection.

Library declarations
PHP
mysqli_get_server_version(mysqli $mysql): int

Parameters

ParameterDescription
mysqlRequired. The mysqli connection returned by mysqli_connect() or mysqli_init().

Return Value

Return ValueDescription
intA packed version number: major*10000 + minor*100 + patch (for example 50744 for 5.7.44).

PHP Examples

Example 1 — Read the Packed Version Number

Print the integer version from a placeholder connection. Output is a fixed sample.

PHP
<?php
$mysqli = mysqli_connect("localhost", "demo_user", "demo_pass", "app_db");

echo mysqli_get_server_version($mysqli), PHP_EOL;

mysqli_close($mysqli);

How It Works

  1. Connect with placeholder login details.
  2. mysqli_get_server_version() returns the packed integer.
  3. 80036 means major 8, minor 0, patch 36.
  4. Close the connection when finished.

Example 2 — Gate a Feature on MySQL 8+

Use a numeric comparison instead of parsing "8.0.36".

PHP
<?php
$mysqli = mysqli_connect("localhost", "demo_user", "demo_pass", "app_db");
$v = mysqli_get_server_version($mysqli);

if ($v >= 80000) {
    echo "MySQL 8 features available.", PHP_EOL;
} else {
    echo "Older server: ", $v, PHP_EOL;
}

mysqli_close($mysqli);

How It Works

  1. Read the packed version into $v.
  2. 80000 represents MySQL 8. 0.0.
  3. The sample server is 80036, so the MySQL 8 branch runs.
  4. This pattern avoids brittle string compares.

Example 3 — Decode Major, Minor and Patch

Split the packed integer back into readable parts for a report.

PHP
<?php
$mysqli = mysqli_connect("localhost", "demo_user", "demo_pass", "app_db");
$v = mysqli_get_server_version($mysqli);

$major = intdiv($v, 10000);
$minor = intdiv($v % 10000, 100);
$patch = $v % 100;

echo "$major.$minor.$patch", PHP_EOL;

mysqli_close($mysqli);

How It Works

  1. Divide by 10000 to get the major version.
  2. The next two digits are the minor version.
  3. The last two digits are the patch number.
  4. The reconstructed text matches a typical mysqli_get_server_info() sample.

Frequently Asked Questions

An integer packed as major*10000 + minor*100 + patch, such as 80036 for MySQL 8.0.36.
Use the integer for comparisons and feature checks. Use the info string when you only need to display the version.
Compare against 50700, which is 5*10000 + 7*100 + 0.
Yes. Pass the mysqli link from connect, new mysqli() or init plus real_connect.
No. Client library version is mysqli_get_client_version().

Next: mysqli_get_warnings()

mysqli_get_warnings() returns the first warning from the last MySQL operation as a mysqli_.

mysqli_get_warnings() tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

8 people found this page helpful