is it possible to set different active database connection after successful login?

I am trying to connect different database, once user is authenticated. I have used following code to connect database after successful login. But connection not remains active.


                        'class' => 'yii\db\Connection',

                        'dsn' => 'mysql:host=localhost;dbname='.$publishedWebsite->db_name,

                        'username' => $publishedWebsite->db_user,

                        'password' =>  $publishedWebsite->db_password,

                        'charset' => 'utf8',



So anyone can suggest me possible solution to resolve my problem.