PHP Tutorial - 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

ParameterIs RequiredDescription
connectionRequired.MySQL connection to use
keyRequired.Path name to the key file
certRequired.Path name to the certificate file
caRequired.Path name to the certificate authority file
capathRequired.Pathname to a directory that contains trusted SSL CA certificates in PEM format
cipherRequired.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/*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);
?>