PHP mysqli_get_proto_info() 函式



定義和用法

mysqli_get_proto_info() 函式用於獲取有關使用的 MySQL 協議(版本)的資訊。

語法

mysqli_get_proto_info($con);

引數

序號 引數及描述
1

con(可選)

這是一個表示與 MySQL 伺服器連線的物件。

返回值

PHP mysqli_get_proto_info() 函式返回一個整數值,指定使用的 MySQL 協議的版本。

PHP 版本

此函式首次在 PHP 5 版本中引入,並在所有後續版本中均有效。

示例

以下示例演示了 mysqli_get_proto_info() 函式(在過程式風格中)的用法 -

<?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);
?>

這將產生以下結果 -

Protocol Version: 10

示例

在面向物件風格中,此函式的語法為 $con -> protocol_version。以下是此函式在面向物件風格中的示例 -

<?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();
?>

這將產生以下結果 -

Protocol Version: 10

示例

以下是 mysqli_get_proto_info() 函式的另一個示例 -

<?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);
   }
?>

這將產生以下結果 -

Connection Established Successfully
Protocol Version: 10

示例

<?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);
?>

這將產生以下結果 -

10
php_function_reference.htm
廣告