O'Reilly logo

CodeIgniter 2 Cookbook by Rob Foster

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required