Accessing Multiple Databases in Craft Is there a way to access another database outside of the one Craft uses for its content? I need to able to access data fields from an external source for a project I'm working on.
From your config/app.php file you could do something like this:

return [
    'components' =&gt; [
        'otherDb' =&gt; [
            'class' =&gt; craft\db\Connection::class,
            'driverName' =&gt; 'mysql',
            'dsn' =&gt; 'mysql:host=localhost;dbname=mydb;port=3306;',
            'username' =&gt; 'myuser',
            'password' =&gt; 'mypass',
            'charset' =&gt; 'utf8',
            'tablePrefix' =&gt; '',
            'enableSchemaCache' =&gt; !YII_DEBUG,
        ],
    ],
]


You might not need all of those depending on what you're doing.

Then from PHP, could access it like:

Craft::$app-&gt;otherDb-&gt;createCommand(...);


And from a template:

{{ craft.app.otherDb... }}