创建 SSL 连接:
<?php
$mysqli = mysqli_init();
if (!$mysqli) {
die("mysqli_init failed");
}
$mysqli -> ssl_set("key.pem", "cert.pem", "cacert.pem", NULL, NULL);
if (!$mysqli -> real_connect("localhost","my_user","my_password","my_db")) {
die("Connect Error: " . mysqli_connect_error());
}
// Some queries...
$mysqli -> close();
?>
查看底部的程序样式示例。
ssl_set() / mysqli_ssl_set() 函数用于使用 SSL 建立安全连接。但是,除非启用 OpenSSL 支持,否则此函数不会执行任何操作。
笔记:该函数必须先调用真实连接()。
笔记:MySQL 本机驱动程序在 PHP 5.3.3 之前不支持 SSL。从 PHP 5.3+ 开始,MySQL 本机驱动程序在 Microsoft Windows 上默认启用。
$mysqli -> ssl_set(
key, cert, ca, capath, cipher)
mysqli_ssl_set(
connection, key, cert, ca, capath, cipher)
Parameter | Description |
---|---|
connection | Required. Specifies the MySQL connection to use |
key | Required. Specifies the path name to the key file |
cert | Required. Specifies the path name to the certificate file |
ca | Required. Specifies the path name to the certificate authority file |
capath | Required. Specifies the pathname to a directory that contains trusted SSL CA certificates in PEM format |
cipher | Required. Specifies a list of allowable ciphers to use for SSL encryption |
返回值: | 永远正确。如果 SSL 设置不正确,真实连接()当您尝试连接时将返回错误 |
---|---|
PHP 版本: | 5+ |
创建 SSL 连接:
<?php
$con = mysqli_init();
if (!$con) {
die("mysqli_init failed");
}
mysqli_ssl_set($con, "key.pem", "cert.pem", "cacert.pem", NULL, NULL);
if (!mysqli_real_connect($con, "localhost", "my_user", "my_password", "my_db")) {
die("Connect Error: " . mysqli_connect_error());
}
// Some queries...
mysqli_close($con);
?>
截取页面反馈部分,让我们更快修复内容!也可以直接跳过填写反馈内容!