Javatpoint Logo
Javatpoint Logo

Database Configuration

In CodeIgniter, go to application/config/databse.php for database configuration file.

Database Configuration1

In database.php file, fill the entries to connect CodeIgniter folder to your database.

Database Configuration2

The config settings are stored in a multi-dimensional array as shown above. Fill out your connection details to connect to database.

You can also specify failover in the situation where main connection cannot be established. This can be specified by setting failover as shown below. You can write as many failovers as you want.

Database Configuration3

Automatically connecting Database

The auto connect feature will load your database class with every page load.

To add auto connect go to application/config/autoload.php and add the word database to library array.

Manually connecting Database

If you need to connect database only in some pages of your project, you can use below code to add the database connectivity in any page, or add it to your class constructor which will make the database globally available for that class.

Connecting multiple Database

If you need to connect more than one database simultaneously, do the following.

Here, group_one and group_two are the group names which will be replaced by your group name.





Please Share

facebook twitter google plus pinterest

Learn Latest Tutorials


B.Tech / MCA