• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[SOLVED] Pre-choose DB

Hi all,

Is there a way to achieve following:
before CI is initialized to let user choose database?

Problem is, while developing new application we are using multiple databases (structure is same, but data differs). So we have ended up with 2+ database (1 for testing, 1 for migration, 1 for new code and so on).

Problem is, that only 1 group of people can work at the same time; for example if I set DB connection to test database, testers can go to work and no one else.

If I change it to migration database, then only those guys can work.

So I would like to present option (in a link, drop down - whatever) to choose to which DB they want to connect?

I don't know if it is important, we are using DB session class;


Now, it may be useful to someone;

I added db_switch.php in /config with:


if (isset($_GET['db'])) {

    $active_group = $_GET['db'];
    $_SESSION['db'] = $active_group;
else if (isset($_SESSION['db'])) {
    $active_group = $_SESSION['db'];
else {
    $_SESSION['db'] = $active_group;

Then, in database.php (also in config) added new DB group and added this line;
$active_group = 'default';
$active_record = TRUE;

Now, when user opens URL, he can add ?db=$dbGroupName and submit it;
CI will then use that DB group.


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

Users browsing this thread:
1 Guest(s)

  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2019 MyBB Group.