mysqli::ssl_set()
(PHP 5, PHP 7)
使用 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 原生驱动的。
参数
- $link
仅以过程化样式:由mysqli_connect()或mysqli_init()返回的链接标识。
- $key
密钥文件的路径
- $cert
证书文件的路径
- $ca
签发机构的证书文件路径
- $capath
指向一个目录的路径,该目录下存放的是受信任的 CA 机构证书 PEM 格式的文件。
- $cipher
SSL 加密允许使用的算法清单
任何未使用的 SSL 参数,可以设置为NULL
。
返回值
此函数永远会返回TRUE
。如果 SSL 的设置有误,那么在调用mysqli_real_connect()函数建立连接的时候才会报错。
参见
- mysqli_options() 设置选项
- mysqli_real_connect() 建立一个 MySQL 服务器连接
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/