I am trying to use / change the database for different organizations / users. In master database, I have db_name for different organizations, I am using the following code to store the db_name in session.
$condition = "subdomain =" . "'" . $data['subdomain'] . "' AND " . "status =1";
$this->db->select('id, db_name');
$this->db->from('sublogin');
$this->db->where($condition);
$this->db->limit(1);
$db_name = $this->db->get()->row()->db_name;
// SET db_name for session
$this->session->set_userdata('db_name', $db_name);
in another model, switch the database
$db_name = $this->session->userdata('db_name');
$this->db->db_select($db_name);
Its working on localhost but not on my live server, it gives error:
A Database Error Occurred Error Number: 1146 Table 'db694230824.users' doesn't exist
I tried to echo the current database and it says the database is not changed.
echo $this->db->database;
die();