[eluser]Unknown[/eluser]
i'm new to CI and i just wanna know is there a way to switch databases in CI,Eg: In login Page, there's a dropdown list that you can specify which database you wanna connect with, view look like this
Code:
[b]<select name="select" id="select" >
<option value="1">DB1</option>
<option value="2">DB2</option>
</select>[/b]
And i got 2 databases in database.php one is defaultthe other is local by default i'm using the default one.
Code:
$active_group = 'default'; $active_record = TRUE;
My question is how do i specify db based on the dropdown value, say if i pick DB1, connect to default one, DB2 goes to local one.... I know how to swtich db manually by :
Code:
$this->load->database('default', TRUE); OR
$this->load->database('local', TRUE);
Since i got different controller and model, how can i achieve this... i did try like: first get the value of dropdownlist in login function:
Code:
$this->load->model('My_Model');
$db = $this->input->post('select')
$this->My_Model->getDB($db);
and then in my model i got function :
Code:
function getDB($db)
{
if($db ==1)
{
$this->db = $this->load->database('default', TRUE);
}
elseif($db ==2)
{
$this->db = $this->load->database('local', TRUE);
}
}
Unfortunately, it doesn't work..... Any help would be much Appreciated!!!!