Welcome Guest, Not a member yet? Register   Sign In
Database Class : connecting to an SSL MySQL server
#1

[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.


Messages In This Thread
Database Class : connecting to an SSL MySQL server - by El Forum - 01-13-2009, 03:06 PM
Database Class : connecting to an SSL MySQL server - by El Forum - 12-07-2009, 03:45 PM
Database Class : connecting to an SSL MySQL server - by El Forum - 12-07-2009, 04:29 PM
Database Class : connecting to an SSL MySQL server - by El Forum - 12-08-2009, 11:55 AM
Database Class : connecting to an SSL MySQL server - by El Forum - 12-08-2009, 04:46 PM
Database Class : connecting to an SSL MySQL server - by El Forum - 12-29-2012, 05:39 AM



Theme © iAndrew 2016 - Forum software by © MyBB