PHP mysqli_ssl_set() Function creates an SSL connection.
PHP mysqli_ssl_set() Function has the following syntax.
mysqli_ssl_set(connection,key,cert,ca,capath,cipher);
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 |
Returns TRUE on success or FALSE on failure.
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/*from w w w .java 2 s. c o m*/
$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);
?>