PHP mysqli_ssl_set () function
Examples
Creating an SSL connection:
<?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());
}
// 一些查询...
mysqli_close($con);
?>
$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());
}
// 一些查询...
mysqli_close($con);
?>
Definition and Usage
mysqli_ssl_set () function is used to create a secure SSL connection. However, this function is effective only if OpenSSL support is enabled.
Note: This function must be in the () mysqli_real_connect called before.
Note: In previous versions of PHP 5.3.3, MySQL Native Driver does not support SSL. Since PHP 5.3+ onwards, enabled by default on Microsoft Windows MySQL Native Driver.
grammar
mysqli_ssl_set( connection,key,cert,ca,capath,cipher ) ;
参数 | 描述 |
---|---|
connection | 必需。规定要使用的 MySQL 连接。 |
key | 必需。规定密钥文件的路径名。 |
cert | 必需。规定认证文件的路径名。 |
ca | 必需。规定认证授权文件的路径名。 |
capath | 必需。规定包含 PEM 格式的可信 SSL CA 认证的目录的路径名。 |
cipher | 必需。规定用于 SSL 加密的可用密码列表。 |
technical details
return value: | Always returns TRUE. If SSL is not installed correctly, the time when you try to connect, mysqli_real_connect () returns an error. |
---|---|
PHP version: | 5+ |
PHP MySQLi Reference Manual