CodeIgniter Forums
Database settings for Model - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: Database settings for Model (/showthread.php?tid=22356)



Database settings for Model - El Forum - 09-06-2009

[eluser]Webjema[/eluser]
As you know the Model can has different DB connections and hence other DB settings for these connections.
I need another DB connection for one of my Models. And I want to keep DB settings together in database.php
How can I send DB settings from database.php to Model?

I looked through database classes and found that database.php is being used once and data from that file is not being saved.
I suggest only one method - to include database.php before creating Model.
Do you have any other ideas?


Database settings for Model - El Forum - 09-06-2009

[eluser]InsiteFX[/eluser]
Hi,

First off you need to read the CodeIgniter Users Guide!
You will find almost everything you need there.

But here is the page from the Users Guide.

CodeIgniter Users Guide Database

Enjoy
InsiteFX


Database settings for Model - El Forum - 09-06-2009

[eluser]Webjema[/eluser]
http://ellislab.com/codeigniter/user-guide/general/models.html#conn
Do you understand?


Database settings for Model - El Forum - 09-06-2009

[eluser]Webjema[/eluser]
Or I have to go to Model __constructor and call $this->load->database('group_name'); ?


Database settings for Model - El Forum - 09-07-2009

[eluser]InsiteFX[/eluser]
Hi,

you can setup your config database.php like this.

Code:
$active_group = "default";
$active_record = TRUE;

// LOCALHOST SITE DEFAULT.
$db['default']['hostname'] = "localhost";
$db['default']['username'] = "username";
$db['default']['password'] = "password";
$db['default']['database'] = "cms";
$db['default']['dbdriver'] = "mysql";
$db['default']['dbprefix'] = "";
$db['default']['pconnect'] = TRUE;
$db['default']['db_debug'] = FALSE;
$db['default']['cache_on'] = FALSE;
$db['default']['cachedir'] = "";
$db['default']['char_set'] = "utf8";
$db['default']['dbcollat'] = "utf8_unicode_ci";

// LIVE SITE PRODUCTION.
$db['production']['hostname'] = "localhost";
$db['production']['username'] = "username";
$db['production']['password'] = "password";
$db['production']['database'] = "myotherdatabase";
$db['production']['dbdriver'] = "mysql";
$db['production']['dbprefix'] = "";
$db['production']['pconnect'] = TRUE;
$db['production']['db_debug'] = FALSE;
$db['production']['cache_on'] = FALSE;
$db['production']['cachedir'] = "";
$db['production']['char_set'] = "utf8";
$db['production']['dbcollat'] = "utf8_unicode_ci";

Change production to your other own name then you can load the one you want.

Enjoy
InsiteFX