M
M
marble2015-04-25 14:09:59
Yii
marble, 2015-04-25 14:09:59

How to connect to a db pack on yii2 bypassing the configuration file?

Hello.
I am developing an application in yii2. It acts as an aggregator for several projects. Its functionality should include the ability to connect to the database of these projects, and the connection settings should be in the database itself so that the user can operate with them without editing files. I saw how new connections to the database are added in yii2 through the config, but this is somewhat different. New projects can be added, corrected, deleted and edited each time the config is a little bit tricky. So, the question is: how to create a connection to the database bypassing the configuration file, i.e. so let's say, on the fly, taking settings from the main database?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander N++, 2015-04-25
_

$connection = new \yii\db\Connection([
    'dsn' => $dsn,
    'username' => $username,
    'password' => $password,
]);
$connection->open();

www.yiiframework.com/doc-2.0/yii-db-connection.html

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question