Welcome Guest, Not a member yet? Register   Sign In
[SOLVED] Pre-choose DB
#1

[eluser]smilie[/eluser]
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;

Thanks!
Smilie
#2

[eluser]smilie[/eluser]
Now, it may be useful to someone;

I added db_switch.php in /config with:

Code:
session_start();

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;
Code:
$active_group = 'default';
require_once('db_switch.php');
$active_record = TRUE;

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

Cheers,
Smilie




Theme © iAndrew 2016 - Forum software by © MyBB