[eluser]Matthieu Fauveau[/eluser]
Hi guys,
I had to make a remote connection to an SSL enabled MySQL server with CodeIgniter. Unfortunately, the database class doesn't include that functionnality yet. Here is the modification I have done to get this to work.
In the file /ci/database/drivers/mysqli/mysqli_driver.php, at line 63, replace:
Code:
return @mysqli_connect($this->hostname, $this->username, $this->password, $this->database, $this->port);
by the following:
Code:
$init = mysqli_init();
mysqli_options($init, MYSQLI_OPT_CONNECT_TIMEOUT, 5);
mysqli_ssl_set($init, '/etc/ssl/mysql/client-key.pem', '/etc/ssl/mysql/client-cert.pem', '/etc/ssl/mysql/ca-cert.pem', NULL, NULL);
@mysqli_real_connect($init, $this->hostname, $this->username, $this->password, $this->database, $this->port);
if(mysqli_connect_errno())
{
return FALSE;
}
else
{
return $init;
}
Of course /etc/ssl/mysql/client-key.pem, client-cert.pem and ca-cert.pem needs to be replaced to match the location of your files.
Unfortunately this is not very handy because every time you will update CodeIgniter you will need to remember that you need to edit that file. It would be nice to have that possibility included in the next release of CI... don't you think ?
There is not much use of mysqli whithout SSL support otherwise...
Regards,
Matt.