當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


PHP mysqli_ssl_set()用法及代碼示例


定義和用法

這個mysqli_ssl_set()函數使用 SSL 與 MySQL 服務器建立安全連接。

用法

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

參數

Sr.No 參數及說明
1

con(Mandatory)

這是一個表示與 MySQL 服務器的連接的對象。

2

key(Mandatory)

這是一個字符串變量,表示 key 文件的路徑名稱。

3

cert(Mandatory)

這是一個字符串變量,表示證書文件的名稱。

4

ca(Mandatory)

這是一個字符串變量,表示證書頒發機構文件的路徑名稱。

5

capath(Mandatory)

這是一個字符串變量,表示包含 PEM 格式的 SSL CA 證書的目錄的路徑名稱。

6

cipher(Mandatory)

允許加密的密碼列表。

返回值

此函數返回布爾值,成功時為真,失敗時為假。

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();以下是麵向對象樣式 $minus 中此函數的示例;

<?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 mysqli_ssl_set() Function。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。