We now have a youtube channel. Subscribe!

PHP | mysqli_ssl_set() Function

PHP mysqli_ssl_set() Function


Hello folks! welcome back to a new edition of our tutorial on PHP. In this tutorial guide, we are going to be studying about the PHP mysqli_ssl_set() Function.

The built-in PHP mysqli_ssl_set() function establishes a secured connection by using SSL with MYSQL server.

Syntax

Following below is the syntax to use this function -

mysqli_ssl_set($con, $key, $cert, $ca, $capath, $cipher);


Parameter Details

Sr.NoParameter & Description
1

con(Mandatory)

This is an object representing a connection to MySQL Server.

2

key(Mandatory)

This is a string variable representing the name of the path to the key file.

3

cert(Mandatory)

This is a string variable representing the name of the certificate file.

4

ca(Mandatory)

This is a string variable representing the name of the path to the certificate authority file.

5

capath(Mandatory)

This is a string variable representing the name of the path to the directory containing the SSL CA certificates in PEM format.

6

cipher(Mandatory)

List of ciphers that are allowed for the encryption.


Return Value

This built-in PHP function returns true on success and false on failure.

PHP Version

This PHP function was first introduced in PHP version 5 and works in all the later versions.

Example1

The following below is an example which shows the usage of the mysqli_ssl_set() function (in a procedural style) -

<?php
   //Creating a connection
   $con = new mysqli("localhost", "root","password","test");

   //Securing the connection
   $con->ssl_set("key.pem", "cert.pem", "cacert.pem", NULL, NULL);

   //Creating the connection
   $con = $con->real_connect("localhost","root","password","test");
   if($con){
      print("Connection Established Successfully");
   }else{
      print("Connection Failed ". mysqli_connect_error());
   }
?>

Output

When the above code is executed, it will produce the following result -

Connection Established Successfully

Example2

In object oriented style the syntax of this built-in PHP function is $con->ssl_set(); The following is the example of this PHP function in object oriented style $minus;

<?php
   //Creating a connection
   $con = new mysqli("localhost", "root","password","test");

   //Securing the connection
   $con->ssl_set("key.pem", "cert.pem", "cacert.pem", NULL, NULL);

   //Creating the connection
   $con = $con->real_connect("localhost","root","password","test");
   if($con){
      print("Connection Established Successfully");
   }else{
      print("Connection Failed ". mysqli_connect_error());
   }
?>

Output

When the above code is executed, it will produce the following result -

Connection Established Successfully


Alright guys! This is where we are going to be rounding up for this tutorial post. In our next tutorial, we are going to be discussing about the PHP mysqli_stat() Function.

Do feel free to ask your questions where necessary and we will attend to them as soon as possible. If this tutorial was helpful to you, you can use the share button to share this tutorial.

Do follow us on our various social media handles available and also subscribe to our newsletter to get our tutorial posts delivered directly to your emails.

Thanks for reading and bye for now.

Post a Comment

Hello dear readers! Please kindly try your best to make sure your comments comply with our comment policy guidelines. You can visit our comment policy page to view these guidelines which are clearly stated. Thank you.
© 2023 ‧ WebDesignTutorialz. All rights reserved. Developed by Jago Desain