sql >> Base de Datos >  >> RDS >> PostgreSQL

Yii2:¿cómo especificar múltiples esquemas de base de datos?

Puedes configurar más de uno en componentes

      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',
          ],

      ],
  ];

y puedes referirte a cada uno usando

 \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-bases de datos.html

para postgresql puedes probar

      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
                ]
              ],
          ],

      ],
  ];