0

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);

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

1 Comment

i want to use datamapper also

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.