Hi Team,
Can you please help me…I have some doubts.Below mentioned the list
Login process using one database after that using another database how to do this process.
After login second database dynamically changing.
It is possible login based database selection
alirz23
(Ali Raza)
January 21, 2017, 4:54pm
2
A simple approach would be to setup the secondary database in config/web.php under components much like you setup your primary database having that setup.
<?php
return [
// ...
'components' => [
// ...
'db' => [
'class' => 'yii\db\Connection',
'dsn' => 'mysql:host=localhost;dbname=users_databaes',
'username' => 'root',
'password' => '',
'charset' => 'utf8',
],
'db2' => [
'class' => 'yii\db\Connection',
'dsn' => 'mysql:host=localhost;dbname=prdoucts_database',
'username' => 'root',
'password' => '',
'charset' => 'utf8',
]
// ...
]
// ...
];
how do we make use of these connections is simply matter of chaning getDb in your user model
class User extends ActiveRecord
{
public static function getDb()
{
// use the "db2" application component
return \Yii::$app->db2;
}
}
Your other models will user db by default, I think that should pretty straight forward to understand
alirz23:
A simple approach would be to setup the secondary database in config/web.php under components much like you setup your primary database having that setup.
<?php
return [
// ...
'components' => [
// ...
'db' => [
'class' => 'yii\db\Connection',
'dsn' => 'mysql:host=localhost;dbname=users_databaes',
'username' => 'root',
'password' => '',
'charset' => 'utf8',
],
'db2' => [
'class' => 'yii\db\Connection',
'dsn' => 'mysql:host=localhost;dbname=prdoucts_database',
'username' => 'root',
'password' => '',
'charset' => 'utf8',
]
// ...
]
// ...
];
how do we make use of these connections is simply matter of chaning getDb in your user model
class User extends ActiveRecord
{
public static function getDb()
{
// use the "db2" application component
return \Yii::$app->db2;
}
}
Your other models will user db by default, I think that should pretty straight forward to understand
thanks for your reply…but i am asking second db dynamic selection after second db choose over all application second db only active.how to do…