PHP Conference Japan 2024

mysqli::ssl_set

mysqli_ssl_set

(PHP 5, PHP 7, PHP 8)

mysqli::ssl_set -- mysqli_ssl_set用於使用 SSL 建立安全連線

說明

物件導向風格

public mysqli::ssl_set(
    ?字串 $key,
    ?字串 $certificate,
    ?字串 $ca_certificate,
    ?字串 $ca_path,
    ?字串 $cipher_algos
): true

程序式風格

mysqli_ssl_set(
    mysqli $mysql,
    ?字串 $key,
    ?字串 $certificate,
    ?字串 $ca_certificate,
    ?字串 $ca_path,
    ?字串 $cipher_algos
): true

用於建立使用 SSL 的安全連線。它必須在 mysqli_real_connect() 之前呼叫。除非啟用 OpenSSL 支援,否則此函式無效。

參數

mysql

僅限程序式風格:由 mysqli_connect()mysqli_init() 返回的 mysqli 物件

key

金鑰檔案的路徑名稱。

certificate

憑證檔案的路徑名稱。

ca_certificate

憑證授權單位檔案的路徑名稱。

ca_path

包含 PEM 格式的受信任 SSL CA 憑證的目錄路徑名稱。(PEM 為 Privacy-Enhanced Mail 的縮寫)

cipher_algos

允許用於 SSL 加密的密碼清單。

返回值

總是返回 true。如果 SSL 設定不正確,mysqli_real_connect() 將在您嘗試連線時返回錯誤。

另請參閱

新增註釋

使用者提供的註釋 1 則註釋

quackfish at gmail dot com
9 年前
請注意,5.7.3 之前的 MySQL 版本並不要求伺服器使用 SSL [1]。對於 PHP,如果連線降級為純文字,客戶端不會拋出錯誤 [2]

[1] https://mysqldev.dev.org.tw/doc/refman/5.7/en/encrypted-connection-options.html#option_general_ssl
[2] http://www.idontplaydarts.com/2015/03/mysql-with-ssl-does-not-protect-against-active-mitm/
To Top