1This is default database :
2
3$db['default'] = array(
4 ....
5 ....
6 'database' => 'mydatabase',
7 ....
8);
9Add another database at the bottom of database.php file
10
11$db['second'] = array(
12 ....
13 ....
14 'database' => 'mysecond',
15 ....
16);
17
18In autoload.php config file
19
20$autoload['libraries'] = array('database', 'email', 'session');
21
22The default database is worked fine by autoload the database library but second database load and connect by using constructor in model and controller...
23
24<?php
25 class Seconddb_model extends CI_Model {
26 function __construct(){
27 parent::__construct();
28 //load our second db and put in $db2
29 $this->db2 = $this->load->database('second', TRUE);
30 }
31
32 public function getsecondUsers(){
33 $query = $this->db2->get('members');
34 return $query->result();
35 }
36
37 }
38?>
39
40/*
41I hope it will help you.
42Namaste
43Stay Home Stay Safe
44*/