setting database user, password and schema on the fly


I have a Yii2 basic application where I’d like to change the used database credentials after the user has logged in to the username and password the user has entered.

The schema name I derive from a manually made database call (I use Postgresql) using the entered credentials where I retrieve the search_path, the success of this call is the password validation at the same time…

I can set the Yii::$app->db->username, Yii::$app->db->password and Yii::$app->db->schemaMap[‘pgsql’][‘defaultSchema’] to the entered values in the models/LoginForm, but these are not used in subsequent CRUD I call from the menu…

I set session variables for all three in models/LoginForm, as I need these values elsewhere (yes, even as a very very newbie I know it is not the safest method, but my users need a certificate to connect anyway) and these are available in other menu calls of old code I am migrating, so it seems that the session variables are available (if that helps).

Any suggestions where I should change it instead?