Welcome Guest, Not a member yet? Register   Sign In
Loading models with database connection array
#1

[eluser]textnotspeech[/eluser]
I have built a CMS for my customers and it's been working great (built with CI 1.5.4 and upgraded to 1.6.1). I have a database for the CMS itself for miscellaneous settings and customer data and another database (on another server) that is the client's site database. The default database is setup in the config file (pconnect is FALSE and I'm not autoloading). The client databases are dynamically loaded from session data with the $this->load->model('table', '', $config) method. The $config array is built by a library that grabs the appropriate session data. This has been working fine and all of a sudden (I don't know what I must've done but I apparently f-ed something up and this is after a successful upgrade to 1.6.1) it seems to be looking for client db info in the cms database. I've been pulling my hair out trying to debug this but I am now calling on Code Igniters for suggestions. I have searched the forums for "multiple databases" and "dynamically load model" to give me insight and it's mostly n00b problems. I've double checked all the code I can think of and it appears to be correct but alas it's still broken. Here's the code and process:

Client logs in and all the appropriate connection info is set to session.
At the dashboard (landing page after login), $config settings are built by a library and assigned to an array. The library function that does this looks like this:
Code:
function db_settings() {
     $CI =& get_instance();
     $settings['hostname'] = $CI->session->userdata('host');
     $settings['username'] = $CI->session->userdata('db_username');
     $settings['password'] = $CI->session->userdata('db_password');
     $settings['database'] = $CI->session->userdata('database');            
     $settings['dbdriver'] = "mysql";
     $settings['dbprefix'] = "";
     $settings['pconnect'] = FALSE;
     $settings['db_debug'] = TRUE;
     return $settings;
}
I pass it to the model like so:
Code:
$conn_settings = $this->conn_settings->db_settings();
$this->load->model('App_settings', '', $conn_settings);

There's no errors up to this point (commenting out all following code with exception of loading the view and consequent missing variables) and everything is fine. I get problems when I attempt to grab data from the client db. This is where it goes wrong:
Code:
$data['some_data'] = $this->App_settings->someFunction();
$this->load->view('application/dashboard', $data);
The view does not load giving me an error:
Table 'cms_database.application_settings' doesn't exist
It should be connected to the client db but it's not. Any suggestions. I know it's gotta be something stupid that I'm just not seeing. Any and all help would be greatly appreciated as my CMS is down and clients can't manage their sites (big problem). I'll repost If I solve this on my own. Thanks.

P.S. I love CI and it's users. It's a great framework and a great community. Cheers to all my fellow Code Igniters.
#2

[eluser]textnotspeech[/eluser]
Got it. There was a bug in the 1.6.1 DB.php file. Currently you have to grab the latest svn copy to fix the bug.
#3

[eluser]wiredesignz[/eluser]
You built an entire application and only posted 3 times?, Man I am really impressed. :lol:

Good work.
#4

[eluser]textnotspeech[/eluser]
It's a great framework with even better documentation. It's really easy unless you get stuck on something stupid at 4:00 in the morning and your brain doesn't work anymore.




Theme © iAndrew 2016 - Forum software by © MyBB