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?>
1<h2><?php echo $title; ?></h2>
2
3<?php echo validation_errors(); ?>
4
5<?php echo form_open('news/create'); ?>
6
7 <label for="title">Title</label>
8 <input type="text" name="title" /><br />
9
10 <label for="text">Text</label>
11 <textarea name="text"></textarea><br />
12
13 <input type="submit" name="submit" value="Create news item" />
14
15</form>
16