I'm trying change the database config at execution time in CI. I've had a little progress,but here we use 3 database managers: ActiveRecord(native from CI),Lumine(a small and old ORM) and Doctrine. I'll try explain better.
In CI exists a database static config file,called database.php. In that file you put the configs,in a matrix format:
$db['config_group']['username']
$db['config_group']['password']
Well,I had to create a Class to generate and return that configuration. So I found a way that I could change it dinamically:
Then in the database.php I call it:
$database = DatabaseManager::initDatabase('address',"user","db");
$active_record = &$database->getActiveRecord();
$active_group = &$database->getActiveGroup();
$db = &$database->exportConfigCI();
Fine! It makes and exports the config for me. Note that I call it with return by reference. Now, it's the time to change it. I have to make a change in the user of DB, according to the type of user logged. So I build a hook of type post_controller_constructor.
The problem: The reference is lost in the middle of the process. No matter how I try, I can't change the values of CI->db object(the object that holds the database attributes). By polymorphism(how I show in the hook) I can do that, but only to ActiveRecord. The others ORM's are based on database.php file. Here I need of return by reference, to change all dependencies linked at database config file.
Doctrine and Lumine config files are linked to the same database.php from CI.
What am I missing? It's possible do what I want?