I want to change databse after login as I am using session for I cannot get database correctly...
And Need to use that database as default in codeigniter......
The Database name, Hostname, Password and Username are commoing from the another database... after login from the databse1 I need to all other stuff from another database dynamically
This is my controller for login:
$unme = $this->db->get_where('database_manage_user_list', array('hospital_id' => $iidd_fnl))->row()->username;
$pss = $this->db->get_where('database_manage_user_list', array('hospital_id' => $iidd_fnl))->row()->password;
$hstnmw = $this->db->get_where('database_manage_user_list', array('hospital_id' => $iidd_fnl))->row()->hostname;
$dbnme = $this->db->get_where('database_manage_user_list', array('hospital_id' => $iidd_fnl))->row()->databasename;
$_SESSION["username"] = $unme;
$_SESSION["password"] = $pss;
$_SESSION["hostname"] = $hstnmw;
$_SESSION["databse"] = $dbnme;
if($grpid == '11' and $by != 'yes'){
redirect('home');
}
And my code in database.php is:
$unme = "";
$pass = "";
$host = "";
$data = "";
if(!isset($_SESSION['username'])){
$unme = "username1";
}else{
$unme = $_SESSION['username'];
}
if(!isset($_SESSION['password'])){
$pass = "password1";
}else{
$pass = $_SESSION['password'];
}
if(!isset($_SESSION['hostname'])){
$host = "localhost";
}else{
$host = $_SESSION['hostname'];
}
if(!isset($_SESSION['databse'])){
$data = "database1";
}else{
$data = $_SESSION['datbase'];
}
$db['default'] = array(
'dsn' => '',
'hostname' => $host,
'username' => $unme,
'password' => $pass,
'database' => $data,
'dbdriver' => 'mysqli',
'dbprefix' => '',
'pconnect' => FALSE,
'db_debug' => (ENVIRONMENT !== 'production'),
'cache_on' => FALSE,
'cachedir' => '',
'char_set' => 'utf8',
'dbcollat' => 'utf8_general_ci',
'swap_pre' => '',
'encrypt' => FALSE,
'compress' => FALSE,
'stricton' => FALSE,
'failover' => array(),
'save_queries' => TRUE
);
But after loging in it is not using database2 it is always using databse1
I don't know why?
Is there any mistake in my code?