PHP mysqli_get_proto_info() Function

Beginner
5 min read
Updated: Nov 2026
3 examples
MySQLi

Definition

In PHP, mysqli_get_proto_info() returns the MySQL protocol version number used by an open connection as an integer.

On modern servers this is commonly 10. The object style is $mysqli->protocol_version. Call it after connecting when you need a quick protocol check.

Syntax

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

PHP
$proto = mysqli_get_proto_info($mysqli);
CallWhat it does
mysqli_get_proto_info($mysqli)Returns the protocol version integer for that connection.
$mysqli->protocol_versionOO property with the same protocol number.
echo mysqli_get_proto_info($mysqli);Prints the protocol version for debugging.

Protocol version is not the same as server version. Server version strings come from mysqli_get_server_info(); protocol info is the wire protocol number.

Library declarations
PHP
mysqli_get_proto_info(mysqli $mysql): int

Parameters

ParameterDescription
mysqlRequired. An open mysqli connection.

Return Value

Return ValueDescription
intThe MySQL protocol version used by the connection.

PHP Examples

Example 1 — Read the Protocol Version

Connect and print mysqli_get_proto_info() from a typical sample.

PHP
<?php
$mysqli = mysqli_connect("localhost", "demo", "secret", "shop");
echo mysqli_get_proto_info($mysqli), PHP_EOL;
mysqli_close($mysqli);

How It Works

  1. A demo connection is opened.
  2. mysqli_get_proto_info() returns the protocol number.
  3. 10 is the common modern sample value.
  4. The connection is closed afterward.

Example 2 — Object Property Form

Read protocol_version from the mysqli object.

PHP
<?php
$mysqli = new mysqli("localhost", "demo", "secret", "shop");
echo $mysqli->protocol_version, PHP_EOL;
$mysqli->close();

How It Works

  1. new mysqli() connects to the demo database.
  2. protocol_version is read as a property.
  3. The sample value matches the procedural call.
  4. close() ends the link.

Example 3 — Show Host and Protocol Together

Combine host info and protocol version in one diagnostic line.

PHP
<?php
$mysqli = mysqli_connect("localhost", "demo", "secret", "shop");
echo mysqli_get_host_info($mysqli), " | proto=",
     mysqli_get_proto_info($mysqli), PHP_EOL;
mysqli_close($mysqli);

How It Works

  1. Host info describes where and how we connected.
  2. Protocol info adds the wire version number.
  3. Both sample values are printed on one line.
  4. Handy for support logs.

Frequently Asked Questions

It returns the MySQL protocol version integer for an open mysqli connection.
Modern MySQL connections commonly report 10, but always read the value from your own server.
Read $mysqli->protocol_version.
No. Server version is a separate string or integer from get_server_info() / get_server_version().
No. You need an open mysqli connection to report its protocol.

Next: mysqli_get_server_info()

mysqli_get_server_info() returns the MySQL server version as a human-readable string for t.

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