Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I have many database connection i have primary connection in the database.php file

$active_group = 'default';
$active_record = TRUE;
$db['default']['hostname'] = 'xxx';
$db['default']['username'] = 'xxx';
$db['default']['password'] = 'xxxx';
$db['default']['database'] = 'xxx';
$db['default']['dbdriver'] = 'mysql';
$db['default']['dbprefix'] = '';
$db['default']['pconnect'] = TRUE;
$db['default']['db_debug'] = TRUE;
$db['default']['cache_on'] = FALSE;
$db['default']['cachedir'] = '';
$db['default']['char_set'] = 'utf8';
$db['default']['dbcollat'] = 'utf8_general_ci';
$db['default']['swap_pre'] = '';
$db['default']['autoinit'] = TRUE;
$db['default']['stricton'] = FALSE;

and i have many more connections .. but i must to config another connections using [Model]

can i pass parameters to database.php?

or can i put like this code in Model

$db['xxx']['hostname'] = 'xxx';
$db['xxx']['username'] = 'xxx';
$db['xxx']['password'] = 'xxxx';
$db['xxx']['database'] = 'xxx';
$db['xxx']['dbdriver'] = 'mysql';
$db['xxx']['dbprefix'] = '';
$db['xxx']['pconnect'] = TRUE;
$db['xxx']['db_debug'] = TRUE;
$db['xxx']['cache_on'] = FALSE;
$db['xxx']['cachedir'] = '';
$db['xxx']['char_set'] = 'utf8';
$db['xxx']['dbcollat'] = 'utf8_general_ci';
$db['xxx']['swap_pre'] = '';
$db['xxx']['autoinit'] = TRUE;
$db['xxx']['stricton'] = FALSE;

$this->load->database('xxx', TRUE);
share|improve this question

1 Answer 1

up vote 1 down vote accepted

I usually define the other db connections in the database.php (as you have it above) then in the model you can call to it like:

$this->xxx_db = $this->load->database('xxx', true); 
$this->xxx_db->set($params);
$sql = $this->xxx_db->insert('table_name');

Doing it this way keeps all the connections in one place - its easier to maintain.

You may also want to see this question: Multiple database connections. I'm not exactly clear on what problem you are having.

share|improve this answer
    
i want to use datamapper also –  dev.bashar Apr 15 '12 at 19:17

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.