CakeFest 2024: The Official CakePHP Conference

mysqli::ssl_set

mysqli_ssl_set

(PHP 5, PHP 7, PHP 8)

mysqli::ssl_set -- mysqli_ssl_set用于使用 SSL 建立安全连接

说明

面向对象风格

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

过程化风格

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

用于使用 SSL 建立安全连接。必须在 mysqli_real_connect() 之前调用。除非启用 OpenSSL 支持,否则此函数不执行任何操作。

参数

mysql

仅以过程化样式:由 mysqli_connect()mysqli_init() 返回的 mysqli 对象。

key

密钥文件的路径

certificate

证书文件的路径

ca_certificate

签发机构的证书文件路径

ca_path

指向一个目录的路径, 该目录下存放的是受信任的 CA 机构证书 PEM 格式的文件。

cipher_algos

SSL 加密允许使用的算法清单

返回值

总是返回 true。如果 SSL 的设置有误,那么当尝试连接时,mysqli_real_connect() 将会返回错误。

参见

add a note

User Contributed Notes 2 notes

up
0
quackfish at gmail dot com
8 years ago
Be warned, MySQL prior to versions 5.7.3 do not require the server to use SSL [1]. In the case of PHP the client won't throw an error if the connection is downgraded to plain-text [2]

[1] https://dev.mysql.com/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/
up
-32
Mike
3 years ago
You no longer need to specify the key - ca or cert to establish a secure connection to MySQL 5.7.3 you can just set ssl
To Top