codeigniter in possible to multiple database connection. codeigniter databases configuration are available in array.

Open the Database.php file

by default codeigniter provide one database connectivity. if you want to create multiple databases then copy the code of default connectivity and paste in Below the code above.

you created second connectivity code in change the database name, database username, and database password.

see blow example

<?php
defined('BASEPATH') OR exit('No direct script access allowed');

$active_group = 'default';
$query_builder = TRUE;

// codeigniter provide default code
$db['default'] = array(
	'dsn'	=> '',
	'hostname' => 'localhost',
	'username' => '',
	'password' => '',
	'database' => '',
	'dbdriver' => 'mysqli',
	'dbprefix' => '',
	'pconnect' => FALSE,
	'db_debug' => (ENVIRONMENT !== 'production'),
	'cache_on' => FALSE,
	'cachedir' => '',
	'char_set' => 'utf8',
	'dbcollat' => 'utf8_general_ci',
	'swap_pre' => '',
	'encrypt' => FALSE,
	'compress' => FALSE,
	'stricton' => FALSE,
	'failover' => array(),
	'save_queries' => TRUE
);

// second connectivity of database
$db['second_db'] = array(
	'dsn'	=> '',
	'hostname' => 'here add second database of hostname',
	'username' => 'here add second database of username',
	'password' => 'here add second database of password',
	'database' => 'here add second database of database name',
	'dbdriver' => 'mysqli',
	'dbprefix' => '',
	'pconnect' => FALSE,
	'db_debug' => (ENVIRONMENT !== 'production'),
	'cache_on' => FALSE,
	'cachedir' => '',
	'char_set' => 'utf8',
	'dbcollat' => 'utf8_general_ci',
	'swap_pre' => '',
	'encrypt' => FALSE,
	'compress' => FALSE,
	'stricton' => FALSE,
	'failover' => array(),
	'save_queries' => TRUE
);

?>

The databases configuration after you can access the database.

//access default database
$this->load->database();
$query = $this->db->query('select * from register');

//access the second database
$second_db= $this->load->database('second_db', TRUE);
$query = $second_db->get('select * from register2');