I'm connecting to my mysql database like this:
$mysqli = new mysqli('76.65.87.64', 'user', 'my_password', 'my_db');
I have 3 certificates to use for a secure SSL connection.
How do I use them with this connection?
I'm connecting to my mysql database like this:
$mysqli = new mysqli('76.65.87.64', 'user', 'my_password', 'my_db');
I have 3 certificates to use for a secure SSL connection.
How do I use them with this connection?
I am putting this answer here because I also encounter the same problem but already deep in the rabbit hole...
In my case, I am maintenance a legacy PHP server that uses mysqli in oop format like OP did.
$mysqli = new mysqli('123.123.123.123', 'user', 'my_password', 'my_db');
And now the requirement is to add SSL/TLS for such connection.
I have searched through the internet for mysqli oop format and ssl capability, sadly it seems like is not possible to do.
To add SSL/TLS, there are a few options to choose ( I choose option 1):
$mysqli = new mysqli('123.123.123.123', 'user', 'my_password', 'my_db');
$mysqli = mysqli_init();
$mysqli->options(MYSQLI_OPT_SSL_VERIFY_SERVER_CERT, true);
$mysqli->ssl_set(NULL, NULL, "xxx.crt", NULL, NULL);
$mysqli->real_connect('123.123.123.123', 'user', 'my_password', 'my_db');
I think the ideal method is to migrate to PDO (optoins 2), but based on the size of the project and time given we need to go with option 1.
To do that, we can use Regex for mass search and replace ( I used Visual Studio Code for the search and replace ):
(\$[^-]+)->real_escape_string(([^)]+))
mysqli_real_escape_string($1,$2)
(\$[^-]+)->query(([^)]+))
mysqli_query($1,$2)
One can also follow the above format to change up the other mysqli oop function used to mysqli procedural. Hope this helps someone, thanks.