Answer the question
In order to leave comments, you need to log in
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
$connection = new \yii\db\Connection([
'dsn' => $dsn,
'username' => $username,
'password' => $password,
]);
$connection->open();
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question