S
S
Sergey Beloventsev2017-03-14 20:59:10
Yii
Sergey Beloventsev, 2017-03-14 20:59:10

How to connect mysql and mongodb databases in yii2 at the same time?

Actually, this is the whole question, except perhaps how to use them, for example, crud models and Active Record in Google, I tried to find information, but I didn’t really find it. Links and tsyki are only welcome.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Shamsudin Serderov, 2017-03-14
@Sergalas

'components' => [
    'dbMySQL' => [
        'class' => '\yii\db\Connection',
        'dsn' => 'mysql:...',
        'username' => '...',
        'password' => '...',
        'charset' => 'utf8',
    ],
    'dbMongo' => [
        'class' => '\yii\mongodb\Connection',
        'dsn' => 'mongodb://...',
    ],
],

Yii::$app->dbMySQL->...
Yii::$app->dbMongo->...

Don't forget to override getDb() in the \yii\db\ActiveRecord and \yii\mongodb\ActiveRecord classes to point to these components if you are using ActiveRecords.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question