I have a simple select
in my View code. It represents list of cities and on my server there're several databases which are responsible for each city. I have my Model code and it takes city_id
. Depends on it I want to connect to database and seek for needed data in it. I've added second database to my components like:
'db' => require(__DIR__ . '/db.php'),
'db2' => require(__DIR__ . '/db_login.php'),
and two files which returns database connection.
File 1:
'class' => 'yii\db\Connection',
'dsn' => $dsn,
'username' => $username,
'password' => $password,
'charset' => 'utf8',
File 2:
'class' => 'yii\db\Connection',
'dsn' => $dsn,
'username' => $username,
'password' => $password,
'charset' => 'utf8',
I want to change my database name somehow dynamically right after users' choice.