Multiple Database Connection in CodeIgniter

You Can Connect to Multiple Database in the same Codeigniter application easily. To use Multiple Database Connections you have to crate multiple Configurations Arrays.

By default CI had following line of code to connect to one database.The default group will be loaded automatically during $this->db call.

So, for another database connection you have to Create Another Configuration Array as shown below.

How to Connect to new Database

For connecting to new database you need to specify the database name along with default connection statement.

How to use new Database

After loading new database , you can perform DB operations as shown below

How to close the Connections

While CodeIgniter intelligently takes care of closing your database connections, you can explicitly close the connection.

I hope you like this Post, Please feel free to comment below, your suggestion and problems if you face - we are here to solve your problems.

I am Arjun from Hyderabad (India). I have been working as a software engineer from last 7+ years, and its my passion to learn new things and implement them as a practice. Aside from work, I likes gardening and spending time with pets. Protection Status