V komponentách můžete konfigurovat více než jednu
return [
'components' => [
'db1' => [
'class' => 'yii\db\Connection',
'dsn' => 'mysql:host=localhost;dbname=testdb1',
'username' => 'demo1',
'password' => 'demo1',
],
'db2' => [
'class' => 'yii\db\Connection',
'dsn' => 'mysql:host=localhost;dbname=testdb2',
'username' => 'demo2',
'password' => 'demo2',
],
],
];
a na každou se můžete odkazovat pomocí
\Yii::$app->db1;
or
\Yii::$app->db2;
http://www.yiiframework.com/doc-2.0 /guide-db-active-record.html
http://www.yiiframework.com/doc-2.0/guide -start-databases.html
pro postgresql můžete zkusit
return [
'components' => [
'db1' => [
'class' => 'yii\db\Connection',
'dsn' => 'pgsql:host=localhost;dbname=testdb1',
'username' => 'demo1',
'password' => 'demo1',
'schemaMap' => [
'pgsql'=> [
'class'=>'yii\db\pgsql\Schema',
'defaultSchema' => 'your_schema1' //specify your schema here
]
],
],
'db2' => [
'class' => 'yii\db\Connection',
'dsn' => 'mysql:host=localhost;dbname=testdb2',
'username' => 'demo2',
'password' => 'demo2',
'schemaMap' => [
'pgsql'=> [
'class'=>'yii\db\pgsql\Schema',
'defaultSchema' => 'your_schema2' //specify your schema here
]
],
],
],
];