For any queries you can reach us at / WhatsApp us: +919158876092

Connect to Database in CodeIgniter


There are two ways to connect with the database:
  1. Automatically connect
  2. Manually connect

Automatically connect

The “auto-connect” feature will load and instantiate the database class with every page load. To enable “auto connecting”, add the word database to the library array in the applications/config/autoload.php file.

$autoload['libraries'] = array('database');

Manually Connect

If you want to load the database in some pages you can connect by adding the following line:


Connecting to Multiple Databases

It is possible to connect more than one database. See the following example.

$DB1 = $this->load->database('group_one', TRUE);
$DB2 = $this->load->database('group_two', TRUE);