Connect through MySQL with SSL

Hi,

How can I connect through MySQL with SSL certificates ?

Thank you !



22.0k

In standard PHP, I will use this :

<?php ini_set ('error_reporting', E_ALL); ini_set ('display_errors', '1'); error_reporting (E_ALL|E_STRICT);

$db = mysqli_init(); mysqli_options ($db, MYSQLI_OPT_SSL_VERIFY_SERVER_CERT, true);

$db->ssl_set('/etc/mysql/ssl/client-key.pem', '/etc/mysql/ssl/client-cert.pem', '/etc/mysql/ssl/ca-cert.pem', NULL, NULL); $link = mysqli_real_connect ($db, 'ip', 'user', 'pass', 'db', 3306, NULL, MYSQLI_CLIENT_SSL); if (!$link) { die ('Connect error (' . mysqli_connect_errno() . '): ' . mysqli_connect_error() . "\n"); } else { $res = $db->query('SHOW TABLES;'); print_r ($res); $db->close(); } ?>

But, what's about Phalcon ?



89.4k

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