English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

PHP Basic Tutorial

PHP Advanced Tutorial

PHP & MySQL

PHP Reference Manual

PHP mysqli_get_proto_info() Function Usage and Example

PHP MySQLi Reference Manual

The mysqli_get_proto_info() function returns the protocol version number used by MySQL

Definition and Usage

mysqli_get_proto_info()The function is used to obtain information about the MySQL protocol (version) used.

Syntax

mysqli_get_proto_info($con);

Parameter

Serial NumberParameters and Description
1

con(Optional)

This is an object representing the connection to the MySQL Server.

Return Value

The PHP mysqli_get_proto_info() function returns an integer value that specifies the version of the MySQL protocol being used.

PHP Version

This function was originally introduced in PHP version5introduced and can be used in all higher versions.

Online Example

The following examples demonstratemysqli_get_proto_info()Usage of the function (procedural style)-

<?php
   //Establish connection
   $con = mysqli_connect("localhost","root","password","mydb");
   //Protocol Version
   $info = mysqli_get_proto_info($con);
   print("Protocol Version: ".$info);
   //Close connection
   mysqli_close($con);
?>

Output Result

Protocol Version: 10

Online Example

In the object-oriented style, the syntax of this function is$con-> protocol_version. The following is an example of this function in object-oriented style-

<?php
   //Establish connection
   $con = new mysqli("localhost","root","password","mydb");
   //Protocol Version
   $info = $con-> protocol_version;
   print("Protocol Version: ".$info);
   //Close connection
   $con -> close();
?>

Output Result

Protocol Version: 10

Online Example

The following ismysqli_get_proto_info()Another example of the function-

<?php
   //Establish connection
   $con = mysqli_connect("localhost","root","password","mydb");
   $code = mysqli_connect_errno();
   if($code){
      print("Connection failed: ".$code);
   }else{
      print("Connection established successfully"."\n");
      $info = mysqli_get_proto_info($con);
      print("Protocol Version: ".$info);
   }
?>

Output Result

Connection established successfully
Protocol Version: 10

Online Example

Return MySQL protocol version:

<?php
   $con = mysqli_connect("localhost","root","password","mydb");
   
   if (mysqli_connect_errno($con)){
      echo "Unable to connect to MySQL: ".mysqli_connect_error();
   }
   echo mysqli_get_proto_info($con);
   
   mysqli_close($con);
?>

Output Result

10

PHP MySQLi Reference Manual