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 );?>The mysqli_ssl_set() function is used to create an SSL secure connection. However, this function only works when OpenSSL support is enabled.
Note: This function must be called before mysqli_real_connect().
Note: In versions prior to PHP 5.3.3, the MySQL Native Driver does not support SSL. As of PHP 5.3+, the MySQL Native Driver is enabled by default on Microsoft Windows.
mysqli_ssl_set( connection,key,cert,ca,capath,cipher ) ;
parameter | describe |
---|---|
connection | Required. Specifies the MySQL connection to use. |
key | Required. Specifies the pathname of the key file. |
cert | Required. Specifies the pathname of the certification file. |
ca | Required. Specifies the path name of the authentication authorization file. |
capath | Required. Specifies the pathname of a directory containing trusted SSL CA certificates in PEM format. |
cipher | Required. Specifies the list of available ciphers for SSL encryption. |
Return value: | Always returns TRUE. If SSL is not installed correctly, mysqli_real_connect() will return an error when you try to connect. |
---|---|
PHP version: | 5+ |