Connection fail in runSqlQuery function when using DSN with SSL
Overview
Connection fail as below when runSqlQuery
function in CRM_Utils_Files is called with DSN string contains SSL parameters.
Cannot open mysqli://user:password@local:3306/civicrm_db?new_link=true&ca=%2Fetc%2Fmysql%2Fdatabase-certificate.pem: DB Error: connect failed
The reason of the issue is that the connect function in the DB class in the PEAR package $db = DB::connect($dsn);
requires stating ssl=true
as an option if we want to connect database using ssl.
The proposal to fix this is to refactor the code in runSqlQuery
function in the CRM_Utils_File class to check if the DSN is SSL DSN then we pass the options array that say ssl=true
as below snippet.
$options['ssl'] = FALSE;
if (CRM_Utils_SQL::isSSLDSN($dsn)) {
$options['ssl'] = TRUE;
}
$db = DB::connect($dsn, $options);
Reproduction steps
The issue can reproduce when installing CiviCRM using Setup class in https://github.com/civicrm/civicrm-setup