I am trying to connect to the database in Phalcon Framework 3.2.4 using SSL. Getting error:
SQLSTATE[HY000] [1045] Access denied for user 'dev_user'@'XXX.XX.XX.XXX' (using password: YES)
My database/config.php:
return new \Phalcon\Config(array(
'database' => array(
'adapter' => 'Mysql',
'host' => 'xxx.rds.amazonaws.com',
'username' => 'dev_user',
'password' => 'XXXXX',
'dbname' => 'dev',
'name' => 'dev',
'charset' => 'utf8')
How do I connect to the database using SSL connection in Phalcon? Its not related to credentials since I tried the following and it worked.
mysqli_ssl_set($con,NULL,NULL,$pemlocation,NULL,'DHE-RSA-XXXX-SHA');
if (!mysqli_real_connect($con,$servername, $username, $password,
$dbname))
{
die("Connect Error: " . mysqli_connect_error());
}
I referred the documentation link: https://forum.phalcon.io/discussion/1221/connect-through-mysql-with-ssl. But did not work out.
At last, found a solution myself, not sure how works.
I think the array values from app/config/config is passed to app/config/services.php.
$di->set('db', function() use ($config) {
$adapter = new \Phalcon\Db\Adapter\Pdo\Mysql(array(
"host" => $config->database->host,
"username" => $config->database->username,
"password" => $config->database->password,
"dbname" => $config->database->dbname,
"charset" => $config->database->charset,
"options" => [ PDO::ATTR_ERRMODE => PDO::ERRMODE_WARNING, PDO::MYSQL_ATTR_SSL_CA => "/home/ubuntu/YOUR_PEM_FILE_HERE" ]
));
return $adapter;
});
And it worked. Hope it helps others who will need to enable an SSL connection to RDS for MySQL.