PHP mysqli_ssl_set() function is used to establish secure connections using SSL.
Syntax
bool mysqli_ssl_set(connection,key,cert,ca,capath,cipher);
Parameter | Description |
---|---|
connection : | Required parameter. The MySQL connection to be used |
key : | Required parameter. The path name to the key file. |
cert : | Required parameter. The path name to the certificate file. |
ca : | Required parameter. The path name to the certificate authority file. |
capath : | Required parameter. The pathname to a directory that contains trusted SSL CA certificates in PEM format. |
cipher : | Required parameter. A list of allowable ciphers to use for SSL encryption. |
Return Values : | Returns TRUE value. If SSL setup is incorrect mysqli_real_connect() will return an error when you attempt to connect. |
<?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","user","password","db")){ die("Connect Error: " . mysqli_connect_error()); } mysqli_close($con); ?>