Database Configuration

Codingox has a config file that lets you store your database connection values (username, password, database name, etc.). The config file is located at config/database.php.

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

$db['default'] = array(
        'hostname' => 'localhost',
        'username' => 'root',
        'password' => '',
        'database' => 'database_name',
        'driver'   => 'mysqli',
);

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:

$db['test'] = array(
        'hostname' => 'localhost',
        'username' => 'root',
        'password' => '',
        'database' => 'database_name',
        'driver'   => 'mysqli',
);

Note

The name ‘test’ is arbitrary. It can be anything you want. By default we’ve used the word “default” for the primary connection, but it too can be renamed to something more relevant to your project.

Explanation of Values:

Name Config Description
hostname The hostname of your database server. Often this is ‘localhost’.
username The username used to connect to the database.
password The password used to connect to the database.
database The name of the database you want to connect to.
driver The database type. ie: mysqli, postgre, odbc, etc. Must be specified in lower case.

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.