PHP mysqli_ssl_set() 函式



定義和用法

mysqli_ssl_set() 函式使用 SSL 建立與 MySQL 伺服器的 安全連線。

語法

mysqli_ssl_set($con, $key, $cert, $ca, $capath, $cipher);

引數

序號 引數及描述
1

con(必填)

表示與 MySQL 伺服器連線的物件。

2

key(必填)

表示金鑰檔案路徑的字串變數。

3

cert(必填)

表示證書檔案的字串變數。

4

ca(必填)

表示證書頒發機構檔案路徑的字串變數。

5

capath(必填)

表示包含 PEM 格式 SSL CA 證書的目錄路徑的字串變數。

6

cipher(必填)

允許用於加密的密碼列表。

返回值

此函式返回布林值,成功時為 true,失敗時為 false

PHP 版本

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

示例

以下示例演示了 mysqli_ssl_set() 函式的用法(過程式風格):

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

   //Securing the connection
   $con->ssl_set("key.pem", "cert.pem", "cacert.pem", NULL, NULL);

   //Creating the connection
   $con = $con->real_connect("localhost","root","password","test");
   if($con){
      print("Connection Established Successfully");
   }else{
      print("Connection Failed ". mysqli_connect_error());
   }
?>

這將產生以下結果:

Connection Established Successfully

示例

在面向物件風格中,此函式的語法為 $con->ssl_set(); 以下是此函式在面向物件風格中的示例:

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

   //Securing the connection
   $con->ssl_set("key.pem", "cert.pem", "cacert.pem", NULL, NULL);

   //Creating the connection
   $con = $con->real_connect("localhost","root","password","test");
   if($con){
      print("Connection Established Successfully");
   }else{
      print("Connection Failed ". mysqli_connect_error());
   }
?>

這將產生以下結果:

Connection Established Successfully
php_function_reference.htm
廣告