CodeIgniter Forums

Full Version: Setting up 2 databases
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi there, 

I am just trying to setup another database within my project. I have done the following within database.php

PHP Code:
$active_group 'default';
$query_builder TRUE;

$db['default'] = array(
    <
details of standard database in here>
);

$db2['default'] = array(
    <
details of 2nd database in here>
); 

I have taken out the details so that its not massive.  I have tried to connect to it but it just errors with cannot find $db2 and I am getting no where.

Can anyone show me how I can connect to this second database so I can get information from it.

Thanks,

Doomie
(03-07-2016, 12:19 PM)Your config: Wrote: [ -> ]
PHP Code:
$active_group 'default';
$query_builder TRUE;

$db['db1_name'] = array(
    <
details of standard database in here>
);

$db['db2_name'] = array(
    <
details of 2nd database in here>
); 

In your models...

PHP Code:
$db1 $this->load->database('db1_name'true);
$db2 $this->load->database('db2_name'true); 

Access with:
PHP Code:
$q1 $db1->query(...)->... or with other methods
$q2 
$db2->query()... etc