User selectable database

Due to how the data I work on is located I need to be able for a user to select the database to use on a per user case.

I have looked at guides on how to use several databases but this does not exactly fit my problem. The system can have an arbitrary number of databases and I need to easily be able to switch between them.

My initial though was to modify the main configuration file (config/main.php) so the name of the selected database is fetched from every users cookie and updated accordingly. The problem was that


is undefined in that file, making it impossible to read a users cookie.

Is this even a remotely realistic idea to solve this problem? Any idea on how this can be solved?



CActiveRecord exposes a public getDbConnection() method so you could override this in your active record models to dynamically create/return a CDbConnection instance

Thanks for your response. This seems to be a much cleaner solution than what i tried.

I have one question though. When is this getDbConnection() called? I fear that it will create a new database connection for every access to the database, or is it one call per model created?