Connecting to multiple databases

There may be times when you require your application to connect to more than one database or database server. For example, imagine you managed an online shop, and you may wish to have one database to handle customer orders, billing, invoicing, and so on, and another database to store and maintain product and stock information. CodeIgniter can be configured to use many database instances, and the following section shows how you do it.

Getting ready

In order to let CodeIgniter interact with two or more databases, we'll need to amend a few settings in the config file at:

  • /path/to/codeigniter/application/config/database.php

Scroll down to the bottom of the file and copy the following into it. Remember to replace hostname ...

Get CodeIgniter 2 Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.