Answer the question
In order to leave comments, you need to log in
How to connect to multiple databases at once?
<?php
return [
'components' => [
'db' => [
'class' => 'yii\db\Connection',
'dsn' => 'mysql:host=localhost;dbname=name',
'username' => 'login',
'password' => 'password',
'charset' => 'utf8',
],
],
];
Answer the question
In order to leave comments, you need to log in
In the config write:
<?php
return [
'components' => [
'db' => [
'class' => 'yii\db\Connection',
'dsn' => 'mysql:host=localhost;dbname=name',
'username' => 'login',
'password' => 'password',
'charset' => 'utf8',
],
'db2' => [
'class' => 'yii\db\Connection',
'dsn' => 'pgsql:host=localhost;dbname=db2',
'username' => 'user',
'password' => 'pass',
'charset' => 'utf8',
],
];
public static function getDb()
{
return Yii::$app->db2;
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question