⚠ In case you've missed it, we have migrated to our new website, with a brand new forum. For more details about the migration you can read our blog post for website migration. This is an archived forum. ⚠

  •     

profile picture

Question: How to make a dynamic switch database?



carloscandreva
  • profile picture
  • Member

Posted 04 June 2013 - 14:03 PM

I have the following problem: I need alter dynamically some settings of the file database.php, I thought I'd build a function within the database.php to accomplish this from variables, but it did not work, the database.php does not accept this alteration, I'm a little lost :S, I need to set the hostname, database, user and password by a function based on a table of other database, so I have to enter into database1 see this settings and set into a second database configuration, how I will make this? There a way to do this?

 

 

Sorry about the bad english :(


davidoster
  • profile picture
  • Member

Posted 04 June 2013 - 22:08 PM

Hello and welcome.

What you ask is a very generic CodeIgniter question and not a Grocery CRUD question.

Quick answer: Theoretically you don't change on the fly the contents of the database.php and to be honest with you why should you?

Since you can read the new credentials from one database why don't you directly connect with these?

You don't need to go via the database.php. CI let's you connect manually. Just read the CI manuals.


carloscandreva
  • profile picture
  • Member

Posted 06 June 2013 - 11:54 AM

This answer resolves perfect my problem xD, thank you very much,sorry about the newbie question. I need multiple databases because of a strange rule of the system that forces me log into a database to see which client will use the system and after this, log into a database specific of this cliente, well with this will resolve all 

 

$dsn = 'dbdriver://username:password@hostname/database';

$this->load->database($dsn);

 

Thank you again :D