MySQLi - SSL Set



Syntax

bool mysqli_ssl_set ( 
   mysqli $link , string $key , string $cert , string $ca , string $capath , string $cipher )

Definition and Usage

It is used for establishing secure connections using SSL

Example

Try out following example −

<?php
   $servername = "localhost:3306";
   $username = "root";
   $password = "";
   $dbname = "TUTORIALS";
   $con = mysqli_init();

   if (!$con){
      die("mysqli_init failed");
   }
   mysqli_ssl_set($con,"key.pem","cert.pem","cacert.pem",NULL,NULL); 
   $conn = new mysqli($servername, $username, $password, $dbname);
   
   if (!$conn->real_connect($con,$servername, $username, $password, $dbname)) {
      die('Connect Error (' . mysqli_connect_errno() . ') '. mysqli_connect_error());
   }
   echo "Database connected";
   printf("Client version: %d\n", mysqli_get_client_version());

   mysqli_close($con);
?>

The sample output of the above code should be like this −

Database connected Client version: 50011
mysqli_useful_functions.htm
Advertisements