Create an SSL connection in PHP

Description

The following code shows how to create an SSL connection.

Example


  //from w  ww . j  a va  2 s  .  c  om
<?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","root","","test")){
         die("Connect Error: " . mysqli_connect_error());
     }
    
     // Some queries...
    
     mysqli_close($con);
?>

The code above generates the following result.





















Home »
  PHP Tutorial »
    MySQL »




MySQLi
MySQLi Object Oriented