略微加速

PHP官方手册 - 互联网笔记

PHP - Manual: mysqli::ssl_set

2024-05-03

mysqli::ssl_set

mysqli_ssl_set

(PHP 5, PHP 7, PHP 8)

mysqli::ssl_set -- mysqli_ssl_set使用 SSL 建立到数据库之间的安全连接

说明

面向对象风格

mysqli::ssl_set(
    string $key,
    string $cert,
    string $ca,
    string $capath,
    string $cipher
): bool

过程化风格

mysqli_ssl_set(
    mysqli $link,
    string $key,
    string $cert,
    string $ca,
    string $capath,
    string $cipher
): bool

使用 SSL 建立到数据库之间的安全连接, 必须在调用 mysqli_real_connect() 函数之前调用此函数。 除非启用 OpenSSL 支持,否则此函数无任何作用。

需要注意的是,在 PHP 5.3.3 之前的版本中, MySQL 原生驱动不支持建立 SSL 连接, 所以,在使用 MySQL 原生驱动的时候,调用此函数会产生错误。 从 PHP 5.3 开始,在 Windows 平台上,默认是启用 MySQL 原生驱动的。

参数

mysql

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

key

密钥文件的路径

cert

证书文件的路径

ca

签发机构的证书文件路径

capath

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

cipher

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

任何未使用的 SSL 参数,可以设置为 null

返回值

此函数永远会返回 true。 如果 SSL 的设置有误,那么在调用 mysqli_real_connect() 函数建立连接的时候才会报错。

参见

add a noteadd a note

User Contributed Notes 2 notes

up
0
quackfish at gmail dot com
7 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
-7
Mike
2 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

官方地址:https://www.php.net/manual/en/mysqli.ssl-set.php

北京半月雨文化科技有限公司.版权所有 京ICP备12026184号-3