• PHP Video Tutorials

PHP mysqli_get_proto_info() Function



Definition and Usage

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

Syntax

mysqli_get_proto_info($con);

Parameters

Sr.No Parameter & Description
1

con(Optional)

This is an object representing a connection to MySQL Server.

Return Values

PHP mysqli_get_proto_info() function returns an integer value specifying the version of MySQL protocol used.

PHP Version

This function was first introduced in PHP Version 5 and works works in all the later versions.

Example

Following example demonstrates the usage of the mysqli_get_proto_info() function (in procedural style) −

<?php
   //Creating a connection
   $con = mysqli_connect("localhost", "root", "password", "mydb");

   //Protocol Version
   $info = mysqli_get_proto_info($con);
   print("Protocol Version: ".$info);

   //Closing the connection
   mysqli_close($con);
?>

This will produce following result −

Protocol Version: 10

Example

In object oriented style the syntax of this function is $con -> protocol_version. Following is the example of this function in object oriented style −

<?php
   //Creating a connection
   $con = new mysqli("localhost", "root", "password", "mydb");

   //Protocol Version
   $info = $con->protocol_version;
   print("Protocol Version: ".$info);

   //Closing the connection
   $con -> close();
?>

This will produce following result −

Protocol Version: 10

Example

Following is another example of the mysqli_get_proto_info() function −

<?php
   //Creating a 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);
   }
?>

This will produce following result −

Connection Established Successfully
Protocol Version: 10

Example

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

This will produce following result −

10
php_function_reference.htm
Advertisements