Możesz skonfigurować więcej niż jeden w komponentach
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',
],
],
];
i możesz odwołać się do każdego z nich za 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
dla postgresql możesz spróbować
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
]
],
],
],
];