CodeIgniter has a config file that lets you store your database
connection values (username, password, database name, etc.). The config
file is located at application/config/database.php. You can also set
database connection values for specific
environments by placing database.php
in the respective environment config folder.

The config settings are stored in a multi-dimensional array with this
prototype:

Some database drivers (such as PDO, PostgreSQL, Oracle, ODBC) might
require a full DSN string to be provided. If that is the case, you
should use the ‘dsn’ configuration setting, as if you’re using the
driver’s underlying native PHP extension, like this:

The reason we use a multi-dimensional array rather than a more simple
one is to permit you to optionally store multiple sets of connection
values. If, for example, you run multiple environments (development,
production, test, etc.) under a single installation, you can set up a
connection group for each, then switch between groups as needed. For
example, to set up a “test” environment you would do this:

The Query Builder Class is globally enabled or
disabled by setting the $query_builder variable in the database
configuration file to TRUE/FALSE (boolean). The default setting is TRUE.
If you are not using the
query builder class, setting it to FALSE will utilize fewer resources
when the database classes are initialized.

$query_builder=TRUE;

Note

that some CodeIgniter classes such as Sessions require Query
Builder to be enabled to access certain functionality.

A default table prefix that should be swapped with dbprefix. This is useful for distributed
applications where you might run manually written queries, and need the prefix to still be
customizable by the end user.

schema

The database schema, defaults to ‘public’. Used by PostgreSQL and ODBC drivers.

The database port number. To use this value you have to add a line to the database config array.

$db['default']['port']=5432;

Note

Depending on what database platform you are using (MySQL, PostgreSQL,
etc.) not all values will be needed. For example, when using SQLite you
will not need to supply a username or password, and the database name
will be the path to your database file. The information above assumes
you are using MySQL.