Unknown
in this tutorial we will Discuss about how to configure database in codeigniter . for configure database in codeigniter you can open config/database.php file
in config/database.php file you can set follwing values
Database is library in codeigniter . database library used in codeigniter for communicate with database.this library provide you many features to communicate with database
'hostname' => 'localhost',
'username' => 'root',
'password' => '',
'database' => 'mypro_ci_tutorial',
$db['default'] = array(
'dsn' => '',
'hostname' => 'localhost',
'username' => 'root',
'password' => '',
'database' => 'mypro_ci_tutorial',
'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' => TRUE
);
There are the following ways to load the database in codeigniter
1. autoload.php
in codeigniter you can load database library in autoload.php file. in autoload.php file you can load database library in library array .this library accessible in complete codeigniter project
$autoload['libraries'] = array('database');
2. Current Controller Constructor :
you can load database library . in current controller constructor using following code .this library accessible only current controller
punlic function __construct()
{
parent::__construct();
$this->load->library('database');
}