Jump to content

Question: How to make a dynamic switch database?


  • Please log in to reply
2 replies to this topic

#1 carloscandreva



  • Members
  • Pip
  • 2 posts

Posted 04 June 2013 - 02: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 :(

#2 davidoster


    Grocery CRUD Ninja

  • Advanced Member
  • PipPipPip
  • 1,068 posts
  • LocationAthens, Greece

Posted 04 June 2013 - 10: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.



rtfm_small.jpg---!!!Please read these guidelines before asking to the forums!!!---



David Oster aka George Pasparakis,

#3 carloscandreva



  • Members
  • Pip
  • 2 posts

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';



Thank you again :D

Also tagged with one or more of these keywords: database

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users