English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
The mysqli_get_proto_info() function returns the protocol version number used by MySQL
mysqli_get_proto_info()The function is used to obtain information about the MySQL protocol (version) used.
mysqli_get_proto_info($con);
Serial Number | Parameters and Description |
---|---|
1 | con(Optional) This is an object representing the connection to the MySQL Server. |
The PHP mysqli_get_proto_info() function returns an integer value that specifies the version of the MySQL protocol being used.
This function was originally introduced in PHP version5introduced and can be used in all higher versions.
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
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
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
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