Config files

CI config files located inside application/config folder.
These files contain some initialized variables that can be used from any other place(like controller,model,view,helper,library).
Here I will discuss some of them that are needed most of the time.

autoload.php

This is the file where we tell CI to load some settings at start.

I always autoload following two library because I work with database and login system.
$autoload['libraries'] = array('database','session');

Most if the time we use URL helper, So keep it in autoload.
$autoload['helper'] = array('url');//URL is CI built-in helper
//If we make own our own helper there should be a .php file in application/helpers folder.

I always use one config file and load in autoload
$autoload['config'] = array('my_config');
//There should be a myconfig.php file in application/config folder.

I have one language file is loaded in autoload
$autoload['language'] = array('my_lang');
//There should be my_lang.php file in application/language/lang_name folder.
//Here lang_name is your language (default english) folder

config.php

config.php already described here

database.php

There is description of all parameter in the commented area. Here I am giving some example

MySQL Example

$db['default']['hostname'] = '127.0.0.1';//localhost
$db['default']['username'] = 'root';//your username
$db['default']['password'] = '';//your password
$db['default']['database'] = 'test';//your default database name
$db['default']['dbdriver'] = 'mysqli';

Oracle Example

$tns = " (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = YOUR_IP)(PORT = 1521)) ) (CONNECT_DATA = (SID = YOUR_SID) ) )";
$db['default']['hostname'] = $tns;
$db['default']['username'] = 'cps';//your username
$db['default']['password'] = '123';//your password
$db['default']['database'] = 'test';//your default database name
$db['default']['dbdriver'] = 'oci8';//oci10/oci11 

You can set as many configuration you want. like

$db['con1']['hostname'] = '127.0.0.1';
................
................
$db['con2']['hostname'] = '192.169.0.1';
................
................
$db['con3']['hostname'] = '180.220.230.1';
................
................

But you have to know how to use them and we will describe it latter in advance model section.

If you use $this->db-> it will use the connection that is set in your $active_group variable

$active_group = 'con1';//it will take your con1 configuration
$active_group = 'con2';//it will take your con2 configuration

Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *