Welcome Guest, Not a member yet? Register   Sign In
Multiple Databases - Where can I store config data from database for application use?
#8

[eluser]ladooboy[/eluser]
@Nick Thanks for the help, it's working now.

I've already had MY_Model so I went again with that approach. I had tried it before, but it wouldn't work. Just to summarize what I did, in case someone else is having the problem.

All my models are extending MY_Model. I am loading this method from MY_Model constructor.

Code:
public function load_user_db()
  {
   $db_name = $this->session->userdata('db_name');
   if ($db_name AND $db_name != '')
   {
     $config = $this->config->item('database_details');
     $config['database'] = $db_name;
     $this->udb = $this->load->database($config,TRUE);

     return TRUE;
   }
    return FALSE;
  }

When I login in my auth_model I do this:

Code:
$database_details = (array)json_decode($user_result->database_details);
  
$this->udb = $this->load->database($database_details,TRUE);    
$query =        $this->udb->get($this->tables['users']);

This is just so that my auth_model has access to the new database as well.

Few things I've came across is:

1. I couldn't make it use the session table in the data1 Databases(because name could be anything), but only in the default session table. This means I also needed to leave these properties for the users database as TRUE, otherwise it would slow down the app and add additional 2 seconds to load the pages.
Code:
$db['localhost']['pconnect'] = TRUE;
$db['localhost']['autoinit'] = TRUE;

2. I had to alter the DB_driver.php to add "$this->db_select();" select db


Messages In This Thread
Multiple Databases - Where can I store config data from database for application use? - by El Forum - 12-30-2012, 06:47 AM



Theme © iAndrew 2016 - Forum software by © MyBB