get_proto_info
In this article, we will focus on the mysqli_get_proto_info() function in PHP, which is used to return the protocol version used by the MySQL connection. We
The mysqli_get_proto_info() function returns the version of the MySQL client/server protocol used by an open connection. The protocol is the low-level wire format the PHP MySQLi extension and the MySQL server use to exchange packets — it is not the same as the MySQL server version (for that, see mysqli_get_server_info()). This page covers the function's syntax, parameters, return value, and a runnable example, plus when you would actually reach for it.
Syntax
The function exists in both the procedural and object-oriented styles:
// Procedural style
mysqli_get_proto_info(mysqli $mysql): int
// Object-oriented style
$mysqli->protocol_versionParameter
$mysql— a MySQLi connection object returned bymysqli_connect()(procedural style only).
Return value
An int holding the protocol version. For all current MySQL servers this is 10, which corresponds to the protocol introduced back in MySQL 3.x and still in use today. The value is a property of the connection, so you must have an open connection before calling it.
Basic example
The classic way to call it is on a live connection. Replace the credentials with your own:
<?php
$mysqli = mysqli_connect("localhost", "username", "password", "database");
if (!$mysqli) {
die("Connection failed: " . mysqli_connect_error());
}
$proto_info = mysqli_get_proto_info($mysqli);
echo "Protocol version: " . $proto_info; // e.g. "Protocol version: 10"
mysqli_close($mysqli);
?>Here we open a connection with mysqli_connect(), verify it succeeded, then pass the connection object to mysqli_get_proto_info(). The function returns an integer that we print with echo.
Object-oriented style
If you use the object-oriented MySQLi API, read the protocol_version property of the connection object instead of calling the procedural function — both return the same value:
<?php
$mysqli = new mysqli("localhost", "username", "password", "database");
if ($mysqli->connect_errno) {
die("Connection failed: " . $mysqli->connect_error);
}
echo "Protocol version: " . $mysqli->protocol_version; // e.g. 10
$mysqli->close();
?>When would I use this?
In day-to-day application code you almost never need the protocol version. It is most useful for:
- Diagnostics and logging — recording connection metadata alongside
mysqli_get_host_info()andmysqli_get_server_info()when troubleshooting a flaky connection. - Sanity checks — confirming a connection is actually established before running queries, since the call only returns a meaningful value on an open link.
For richer connection details, look at these related functions:
mysqli_get_server_info()— the MySQL server version string.mysqli_get_host_info()— the host name and connection type (TCP/IP, socket, etc.).mysqli_get_client_info()— the MySQL client library version.
Conclusion
The mysqli_get_proto_info() function is a simple way to read the integer protocol version (10 on modern servers) of an active MySQLi connection. It is rarely needed in everyday logic but remains handy for diagnostics, logging, and confirming that your application is talking to the database over the expected protocol.