Du kan konfigurera mer än en i komponenter
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',
],
],
];
och du kan referera till var och en med
\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
för postgresql kan du prova
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
]
],
],
],
];