Configuring database in CodeIgniter

This article will show you how to configute database connection in CodeIgniter. You can save your database connection details in database.php file.

Configuring database in CodeIgniter

To connect your application with the database, you need to set the database connection details in the database.php file. You can store more than one connection details in this file.

Configuring database in CodeIgniter – Setting connection details

You can set the database connection details in the database.php file located under root_folder_of_your_project->config folder.

Modify the database.php file as shown below:

$active_group = 'default';
$query_builder = TRUE;
$db['default'] = array(
    'dsn'   => '',
    'hostname' => 'localhost', //server..
    'username' => 'root', //database username
    'password' => '', //database password
    'database' => 'cisite', //Your database name here
    'dbdriver' => 'mysqli',
    'dbprefix' => '',
    'pconnect' => FALSE,
    'db_debug' => (ENVIRONMENT !== 'production'),
    'cache_on' => FALSE,
    'cachedir' => '',
    'char_set' => 'utf8',
    'dbcollat' => 'utf8_general_ci',
    'swap_pre' => '',
    'encrypt' => FALSE,
    'compress' => FALSE,
    'stricton' => FALSE,
    'failover' => array(),
    'save_queries' => FALSE
);

Values used

VALUEDESCRIPTION
hostnameSpecifies the hostname of your database server. In most cases, it is localhost.
usernameSpecifies the username of the database.
passwordSpecifies the password of the database.
databaseSpecifies the database which you are using.
dbprefixSpecifies an optional table prefix which will be added to the table name when running Query Builder queries.
db_debugSpecifies whether the database errors should be displayed. It can have TRUE or FASLE as values.

Share Tweet Send
Loading...