Current Location: Home> Function Categories> mysqli::ssl_set

mysqli::ssl_set

(mysqli_ssl_set) is used to establish a secure connection using SSL
Name:mysqli::ssl_set
Category:MySQLi
Programming Language:php
One-line Description:Used to establish secure connections using SSL.

Definition and usage

ssl_set() / mysqli_ssl_set() function is used to establish a secure connection using SSL. However, this function does nothing unless OpenSSL support is enabled.

Note: This function must be called before real_connect() .

Note: Before PHP 5.3.3, MySQL native drivers did not support SSL. Starting with PHP 5.3+, MySQL native drivers are enabled by default on Microsoft Windows.

Example

Example 1 - Object-Oriented Style

Create an SSL connection:

 <?php
$mysqli = mysqli_init ( ) ;
if ( ! $mysqli ) {
  die ( "mysqli_init failed" ) ;
}

$mysqli -> ssl_set ( "key.pem" , "cert.pem" , "cacert.pem" , NULL , NULL ) ;

if ( ! $mysqli -> real_connect ( "localhost" , "my_user" , "my_password" , "my_db" ) ) {
  die ( "Connect Error: " . mysqli_connect_error ( ) ) ;
}

// Some queries...

$mysqli -> close ( ) ;
?> 

Example 2 - Procedural Style

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 ) ;
?>
Similar Functions
Popular Articles