PHP Function Reference

PHP mysqli $protocol_version Property



The PHP mysqli::$protocol_version / mysqli_get_proto_info() function returns an integer representing the MySQL protocol version used by the connection represented by the mysql parameter.

Syntax

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

//Procedural style
mysqli_get_proto_info(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 protocol version.

Example: Object-oriented style

The example below shows the usage of mysqli::$protocol_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 protocol version
printf("Protocol version: %d\n", $mysqli->protocol_version);

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

The output of the above code will be similar to:

Protocol version: 10

Example: Procedural style

The example below shows the usage of mysqli_get_proto_info() 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 protocol version
printf("Protocol version: %d\n", mysqli_get_proto_info($mysqli));

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

The output of the above code will be similar to:

Protocol version: 10

❮ PHP MySQLi Reference