his is my scenario.
I have a list of all the Clinic using my application in a ‘main’ database. In the ‘main’, information about each clinic is in a table which also contains columns that for, database name, username and password for the DB. The schema structure is the same for each one.
All these clinics will use the single source code, which I am currently developing in Yii2. What I would need is at the time of login, automatically select the corresponding database, from that all the transaction, must be in the database.
I tried saving Database name in the session.
$db_name = "main";
if( isset($_SESSION['db']) ){
$db_name = $_SESSION['db'];
}
$config = [
'components' => [
'db' => [
'class' => 'yii\db\Connection',
'dsn' => 'mysql:host=localhost;dbname='.$db_name,
'username' => 'root',
'password' => '',
'charset' => 'utf8',
],
],
];
it doesn’t work I can’t access the session in config/main.php.
I can’t do the solution because all clinics have the same SERVER_NAME. Change DB connection Dynamically