<p>Silly mistake. I forgot to update AppBehaviors.php to the newest release after moving the attributes logic to db.php:</p>

<pre><code>$dbConnection = new DbConnection();

$dbConnection-&gt;connectionString = $this-&gt;_processConnectionString();
$dbConnection-&gt;emulatePrepare   = true;
$dbConnection-&gt;username         = craft()-&gt;config-&gt;get('user', ConfigFile::Db);
$dbConnection-&gt;password         = craft()-&gt;config-&gt;get('password', ConfigFile::Db);
$dbConnection-&gt;charset          = craft()-&gt;config-&gt;get('charset', ConfigFile::Db);
$dbConnection-&gt;tablePrefix      = $dbConnection-&gt;getNormalizedTablePrefix();
$dbConnection-&gt;driverMap        = array('mysql' =&gt; 'Craft\MysqlSchema');

// Support for Yii's $initSQLs
if ($initSQLs = craft()-&gt;config-&gt;get('initSQLs', ConfigFile::Db))
{
    $dbConnection-&gt;initSQLs = $initSQLs;
}
// See if we have any extra PDO attributes passed in.
if ($attributes = craft()-&gt;config-&gt;get('attributes', ConfigFile::Db))
{
    $dbConnection-&gt;attributes = $attributes;
}

$dbConnection-&gt;init();
</code></pre>

<p>After adding the new lines of code, I was able to connect :)</p>

CC BY-SA 3.0
2016-10-26T14:51:13.627Z
2016-10-26T14:51:13.627Z
Leah Scott
<p>I used to connect to my database over SSL by directly modifying the createDbConnection method in Craft's AppBehavior.php:</p>

<pre><code>$dbConnection = new DbConnection();

$dbConnection-&gt;connectionString = $this-&gt;_processConnectionString();
$dbConnection-&gt;emulatePrepare   = true;
$dbConnection-&gt;username         = craft()-&gt;config-&gt;get('user', ConfigFile::Db);
$dbConnection-&gt;password         = craft()-&gt;config-&gt;get('password', ConfigFile::Db);
$dbConnection-&gt;charset          = craft()-&gt;config-&gt;get('charset', ConfigFile::Db);
$dbConnection-&gt;tablePrefix      = $dbConnection-&gt;getNormalizedTablePrefix();
$dbConnection-&gt;driverMap        = array('mysql' =&gt; 'Craft\MysqlSchema');

// additional attributes to connect over SSL
if (getenv('DB_SSL_ENABLED') == 'true') 
{
    $dbConnection-&gt;attributes   = array(
        PDO::MYSQL_ATTR_SSL_CIPHER =&gt; 'DHE-RSA-AES256-SHA:AES128-SHA',
        PDO::MYSQL_ATTR_SSL_CA     =&gt; CRAFT_CONFIG_PATH . 'rds-combined-ca-bundle.pem',
    );
}

$dbConnection-&gt;init();
</code></pre>

<p>But as of a new Craft <a href="https://craftcms.com/changelog#build2945" rel="nofollow">release</a> there is a native Craft way to do this by setting a new "attributes" key in the database config file. Unfortunately, Craft won't make a connection when I connect using this new method. I get the dreaded <em>Craft can’t connect to the database with the credentials in craft/config/db.php</em> error. My revised db.php looks like this:</p>

<pre><code>$url = parse_url(getenv("DATABASE_URL"));

define(SERVER, $url["host"]);
define(USER, $url["user"]);
define(PASSWORD, $url["pass"]);
define(DATABASE, substr($url["path"], 1));

return array(
    'server' =&gt; SERVER,
    'user' =&gt; USER,
    'password' =&gt; PASSWORD,
    'database' =&gt; DATABASE,
    'tablePrefix' =&gt; 'craft',
    'attributes' =&gt; array(
        PDO::MYSQL_ATTR_SSL_CIPHER =&gt; 'DHE-RSA-AES256-SHA:AES128-SHA',
        PDO::MYSQL_ATTR_SSL_CA     =&gt; CRAFT_CONFIG_PATH . 'rds-combined-ca-bundle.pem',
     )
);
</code></pre>

<p>Not sure what could be going wrong here. Are there additional attributes that need to be set when doing this the Yii way?</p>

CC BY-SA 3.0
2016-10-25T18:40:51.143Z
You're saying your first examples works when modifying AppBehavior directly? Craft is passing the attributes config setting directly into `$dbConnection->attributes` just like you're doing: https://github.com/pixelandtonic/Craft-Release/blob/master/app/etc/behaviors/AppBehavior.php#L830-L834
Brad Bell
CC BY-SA 3.0
2016-10-25T18:42:07.740Z
Any chance you need to set PDO::MYSQL_ATTR_SSL_KEY and PDO::MYSQL_ATTR_SSL_CERT, too? https://dev.mysql.com/doc/refman/5.5/en/using-secure-connections.html
Brad Bell
CC BY-SA 3.0
2016-10-25T20:19:57.817Z
When connecting to RDS it is recommended to use only use the ca cert. And I can confirm the connection works without the other keys since the first code block in AppBehavior can connect.
Leah Scott
CC BY-SA 3.0
2016-10-25T20:20:55.350Z
I'm trying to think of other things that could be going wrong. Does PDO need to be escaped from the Craft namespace? I'm grasping at straws here.
Leah Scott
CC BY-SA 3.0
2016-10-25T20:35:14.573Z
Good question... does `\PDO::` work?
Brad Bell
CC BY-SA 3.0
2016-10-25T20:53:22.400Z
Ahhh Brad I forgot to update AppBehaviors from the latest release after moving the logic to db.php. So sorry. It's always the simplest mistakes that are the most baffling. Well, works fine now. Thanks for the assist.
Leah Scott
CC BY-SA 3.0
2016-10-25T21:55:35.923Z
Ahh, nice.  Can you add that as an official answer in case someone else does the same? :)
Brad Bell
<database><security><ssl>
Problems Securing Database Connection Over SSL
# Problems Securing Database Connection Over SSL

(Asked by: username_0 on 2016-10-25)

I used to connect to my database over SSL by directly modifying the createDbConnection method in Craft's AppBehavior.php:
$dbConnection = new DbConnection();

$dbConnection->connectionString = $this->_processConnectionString();
$dbConnection->emulatePrepare   = true;
$dbConnection->username         = craft()->config->get('user', ConfigFile::Db);
$dbConnection->password         = craft()->config->get('password', ConfigFile::Db);
$dbConnection->charset          = craft()->config->get('charset', ConfigFile::Db);
$dbConnection->tablePrefix      = $dbConnection->getNormalizedTablePrefix();
$dbConnection->driverMap        = array('mysql' => 'Craft\MysqlSchema');

// additional attributes to connect over SSL
if (getenv('DB_SSL_ENABLED') == 'true') 
{
    $dbConnection->attributes   = array(
        PDO::MYSQL_ATTR_SSL_CIPHER => 'DHE-RSA-AES256-SHA:AES128-SHA',
        PDO::MYSQL_ATTR_SSL_CA     => CRAFT_CONFIG_PATH . 'rds-combined-ca-bundle.pem',
    );
}

$dbConnection->init();

But as of a new Craft release there is a native Craft way to do this by setting a new "attributes" key in the database config file. Unfortunately, Craft won't make a connection when I connect using this new method. I get the dreaded Craft can’t connect to the database with the credentials in craft/config/db.php error. My revised db.php looks like this:
$url = parse_url(getenv("DATABASE_URL"));

define(SERVER, $url["host"]);
define(USER, $url["user"]);
define(PASSWORD, $url["pass"]);
define(DATABASE, substr($url["path"], 1));

return array(
    'server' => SERVER,
    'user' => USER,
    'password' => PASSWORD,
    'database' => DATABASE,
    'tablePrefix' => 'craft',
    'attributes' => array(
        PDO::MYSQL_ATTR_SSL_CIPHER => 'DHE-RSA-AES256-SHA:AES128-SHA',
        PDO::MYSQL_ATTR_SSL_CA     => CRAFT_CONFIG_PATH . 'rds-combined-ca-bundle.pem',
     )
);

Not sure what could be going wrong here. Are there additional attributes that need to be set when doing this the Yii way?

**Tags:** database, security, ssl

> **Comments:**
> **username_1**: You're saying your first examples works when modifying AppBehavior directly? Craft is passing the attributes config setting directly into `$dbConnection->attributes` just like you're doing: https://github.com/pixelandtonic/Craft-Release/blob/master/app/etc/behaviors/AppBehavior.php#L830-L834  
> **username_1**: Any chance you need to set PDO::MYSQL_ATTR_SSL_KEY and PDO::MYSQL_ATTR_SSL_CERT, too? https://dev.mysql.com/doc/refman/5.5/en/using-secure-connections.html  
> **username_0**: When connecting to RDS it is recommended to use only use the ca cert. And I can confirm the connection works without the other keys since the first code block in AppBehavior can connect.  
> **username_0**: I'm trying to think of other things that could be going wrong. Does PDO need to be escaped from the Craft namespace? I'm grasping at straws here.  
> **username_1**: Good question... does `\PDO::` work?  
> **username_0**: Ahhh Brad I forgot to update AppBehaviors from the latest release after moving the logic to db.php. So sorry. It's always the simplest mistakes that are the most baffling. Well, works fine now. Thanks for the assist.  
> **username_1**: Ahh, nice.  Can you add that as an official answer in case someone else does the same? :)  

---

## 1 answers

### Answer by username_0 on 2016-10-26. Score: 0 | Accepted answer

Silly mistake. I forgot to update AppBehaviors.php to the newest release after moving the attributes logic to db.php:
$dbConnection = new DbConnection();

$dbConnection->connectionString = $this->_processConnectionString();
$dbConnection->emulatePrepare   = true;
$dbConnection->username         = craft()->config->get('user', ConfigFile::Db);
$dbConnection->password         = craft()->config->get('password', ConfigFile::Db);
$dbConnection->charset          = craft()->config->get('charset', ConfigFile::Db);
$dbConnection->tablePrefix      = $dbConnection->getNormalizedTablePrefix();
$dbConnection->driverMap        = array('mysql' => 'Craft\MysqlSchema');

// Support for Yii's $initSQLs
if ($initSQLs = craft()->config->get('initSQLs', ConfigFile::Db))
{
    $dbConnection->initSQLs = $initSQLs;
}
// See if we have any extra PDO attributes passed in.
if ($attributes = craft()->config->get('attributes', ConfigFile::Db))
{
    $dbConnection->attributes = $attributes;
}

$dbConnection->init();

After adding the new lines of code, I was able to connect :)


---

