Welcome Guest, Not a member yet? Register   Sign In
Setting up 2 databases
#1

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
Reply
#2

http://codeigniter.com/user_guide/databa...cting.html
Simpler is always better
Reply
#3

(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
Reply




Theme © iAndrew 2016 - Forum software by © MyBB