PHP mysqli_get_server_info() Function

Beginner
5 min read
Updated: Nov 2026
3 examples
MySQLi

Definition

In PHP, mysqli_get_server_info() returns the MySQL server version as a human-readable string for the open connection, such as "8.0.36".

Use it when you want a printable version for logs, admin pages or debugging. For a numeric form you can compare in code, prefer mysqli_get_server_version().

Syntax

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

PHP
$version = mysqli_get_server_info($mysqli);
CallWhat it does
mysqli_get_server_info($mysqli)Returns a string like "8.0.36" for the connected server.
echo mysqli_get_server_info($mysqli)Prints the server version text to the browser or terminal.
$info = mysqli_get_server_info($mysqli);Stores the version string so you can log or display it later.

You need a live connection from mysqli_connect(), new mysqli() or mysqli_init() plus mysqli_real_connect(). The string format depends on the server build; do not parse it with fragile string logic when you only need a number.

Library declarations
PHP
mysqli_get_server_info(mysqli $mysql): string

Parameters

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

Return Value

Return ValueDescription
stringThe MySQL server version as text, for example "8.0.36" or "5.7.44-log".

PHP Examples

Example 1 — Print the Server Version String

Connect with placeholders and print the server info string. The output is a fixed sample.

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

if (!$mysqli) {
    echo "Connect failed.", PHP_EOL;
    exit;
}

echo "Server: ", mysqli_get_server_info($mysqli), PHP_EOL;

mysqli_close($mysqli);

How It Works

  1. mysqli_connect() opens a connection with placeholder credentials.
  2. mysqli_get_server_info() reads the version text from that connection.
  3. We print the string for a typical MySQL 8 sample.
  4. mysqli_close() ends the session.

Example 2 — Compare Info String and Version Number

Show both the readable string and the integer version side by side.

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

$asText = mysqli_get_server_info($mysqli);
$asNumber = mysqli_get_server_version($mysqli);

echo "info: ", $asText, PHP_EOL;
echo "version: ", $asNumber, PHP_EOL;

mysqli_close($mysqli);

How It Works

  1. mysqli_get_server_info() gives the printable label.
  2. mysqli_get_server_version() gives a packed integer such as 80036 for 8. 0.36.
  3. Use the integer when you need if ($version >= 80000) style checks.
  4. The values shown are fixed tutorial samples.

Example 3 — Log Server Info at Startup

Store the version in a log-style line when your script starts.

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

$line = "Connected to MySQL " . mysqli_get_server_info($mysqli);
echo $line, PHP_EOL;

mysqli_close($mysqli);

How It Works

  1. After a successful connect, read the server info once.
  2. Build a short message for logs or an admin banner.
  3. The sample line uses a typical 8. 0.36 version string.
  4. Closing the connection is still good practice when you are done.

Frequently Asked Questions

A string with the MySQL server version for the current connection, such as "8.0.36".
mysqli_get_server_info() is human-readable text. mysqli_get_server_version() returns an integer you can compare in code.
Yes. Call it on a mysqli object from mysqli_connect(), new mysqli() or mysqli_init() followed by mysqli_real_connect().
No. Client library details use mysqli_get_client_info() and mysqli_get_client_version().
Yes. Some builds append tags such as "-log" or vendor suffixes. Treat the string as display text, not a strict parser input.

Next: mysqli_get_server_version()

mysqli_get_server_version() returns the MySQL server version as an integer for the open co.

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