PHP mysqli_ssl_set() Function
Definition
PHP mysqli_ssl_set() Function creates an SSL connection.
Syntax
PHP mysqli_ssl_set() Function has the following syntax.
mysqli_ssl_set(connection,key,cert,ca,capath,cipher);
Parameter
Parameter | Is Required | Description |
---|---|---|
connection | Required. | MySQL connection to use |
key | Required. | Path name to the key file |
cert | Required. | Path name to the certificate file |
ca | Required. | Path name to the certificate authority file |
capath | Required. | Pathname to a directory that contains trusted SSL CA certificates in PEM format |
cipher | Required. | A list of allowable ciphers for SSL encryption |
Return
Returns TRUE on success or FALSE on failure.
Example
The mysqli_ssl_set() function establishes secure connections using SSL for the enabled OpenSSL support. This function must be called before mysqli_real_connect().
<?php// w ww .j a v a2s . c om
$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);
?>