w3resource

PHP mysqli: get_proto_info() function

mysqli_get_proto_info() function / mysqli::$protocol_version

The mysqli_get_proto_info() function / mysqli::$protocol_version returns the MySQL protocol version.

Syntax:

Object oriented style

string $mysqli->protocol_version;

Procedural style

int mysqli_get_proto_info ( mysqli $link )

Parameter:

Name Description Required/Optional
connection A link identifier returned by mysqli_connect() or mysqli_init() Required for procedural style only and Optional for Object oriented style

Usage: Procedural style

mysqli_get_proto_info(connection);

Parameter:

Name Description Required/Optional
connection Specifies the MySQL connection to use. Required

Return value:

Returns an integer representing the protocol version.

Version: PHP 5, PHP 7

Example of object oriented style:

<?php
$mysqli = new mysqli("localhost", "user1", "datasoft123");

/* check connection */
if (mysqli_connect_errno()) {
    printf("Connect failed: %s\n", mysqli_connect_error());
    exit();
}

/* print protocol version */
printf("Protocol version: %d\n", $mysqli->protocol_version);

/* close connection */
$mysqli->close();
?>

Output:

Protocol version: 10

Example of procedural style:

<?php
$link = mysqli_connect("localhost", "user1", "datasoft123");

/* check connection */
if (mysqli_connect_errno()) {
    printf("Connect failed: %s\n", mysqli_connect_error());
    exit();
}

/* print protocol version */
printf("Protocol version: %d\n", mysqli_get_proto_info($link));

/* close connection */
mysqli_close($link);
?>

Output:

Protocol version: 10

Example:

<?php
$con=mysqli_connect("localhost","user1","datasoft123","hr");
// Check connection
if (mysqli_connect_errno())
  {
  echo "Failed to connect to MySQL: " . mysqli_connect_error();
  }

echo mysqli_get_proto_info($con);

mysqli_close($con);
?>

Output:

Protocol version: 10

See also

PHP Function Reference

Previous: host_info
Next: server_info



Become a Patron!

Follow us on Facebook and Twitter for latest update.

It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.

https://w3resource.com/php/function-reference/mysqli_protocol_version.php