Connect through MySQL with SSL

Hi,

How can I connect through MySQL with SSL certificates ?

Thank you !



16.5k

In standard PHP, I will use this :

<?php iniset ('errorreporting', EALL); iniset ('displayerrors', '1'); errorreporting (EALL|ESTRICT);

$db = mysqliinit(); mysqlioptions ($db, MYSQLIOPTSSLVERIFYSERVER_CERT, true);

$db->sslset('/etc/mysql/ssl/client-key.pem', '/etc/mysql/ssl/client-cert.pem', '/etc/mysql/ssl/ca-cert.pem', NULL, NULL); $link = mysqlirealconnect ($db, 'ip', 'user', 'pass', 'db', 3306, NULL, MYSQLICLIENTSSL); if (!$link) { die ('Connect error (' . mysqliconnecterrno() . '): ' . mysqliconnecterror() . "\n"); } else { $res = $db->query('SHOW TABLES;'); printr ($res); $db->close(); } ?>

But, what's about Phalcon ?



81.3k

Phalcon does use PDO as database layer, try something like this:

// Create a connection with PDO options
$connection = new \Phalcon\Db\Adapter\Pdo\Mysql(array(
    "host" => "localhost",
    "username" => "root",
    "password" => "sigma",
    "dbname" => "test_db",
    "options" => array(
        PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES \'UTF8\'",
        PDO::MYSQL_ATTR_SSL_CA => "/path/to/ca"
    )
));

http://php.net/manual/en/ref.pdo-mysql.php