PHP mysqli_ssl_set()Functions
Examples
Create 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());
}
// some queries...
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());
}
// some queries...
mysqli_close($con);
?>
Definition and Usage
The mysqli_ssl_set() function is used to create an SSL secure connection. However, this function only works when OpenSSL support is enabled.
Note:The function must bemysqli_real_connect()called before.
Note:In versions before PHP 5.3.3, MySQL Native Driver does not support SSL. Since PHP 5.3+, MySQL Native Driver is enabled by default on Microsoft Windows.
Syntax
mysqli_ssl_set(connection,key,cert,ca,capath,cipher);
| Parameters | Description |
|---|---|
| connection | Required. Specifies the MySQL connection to use. |
| key | Required. Specifies the path name of the key file. |
| cert | Required. Specifies the path name of the certificate file. |
| ca | Required. Specifies the path name of the certificate authority file. |
| capath | Required. Specifies the path name of the directory containing trusted SSL CA certificates in PEM format. |
| cipher | Required. Specifies a list of available ciphers for SSL encryption. |
Technical Details
| Return value: | Always returns TRUE. If SSL is not installed correctly, when you attempt to connect,mysqli_real_connect()an error will be returned. |
|---|---|
| PHP Version: | 5+ |
PHP MySQLi Reference Manual Other Extensions