Skip to content

Setting Database Configuration in CodeIgniter?

Setting Database Configurations in Codeigniter very tiny task , just open database.php within applicationconfig. Set config like below , here database user “root”, password “”(no password), DB Name “db_name”.

if you want to disable persistent connnect just change $db['default']['pconnect'] = TRUE; to $db['default']['pconnect'] = FALSE;

if you want to Hide(disable) Database Error just change $db['default']['db_debug'] = TRUE; to $db['default']['db_debug'] = FALSE;

just like above changes to the configuration values you can change any of the DB config values(settings) any time to the config array.

Here the sample database.php script

$active_group = 'default';
$active_record = TRUE;

$db['default']['hostname'] = 'localhost';
$db['default']['username'] = 'root';
$db['default']['password'] = '';
$db['default']['database'] = 'db_name';
$db['default']['dbdriver'] = 'mysql';
$db['default']['dbprefix'] = '';
$db['default']['pconnect'] = TRUE;
$db['default']['db_debug'] = TRUE;
$db['default']['cache_on'] = FALSE;
$db['default']['cachedir'] = '';
$db['default']['char_set'] = 'utf8';
$db['default']['dbcollat'] = 'utf8_general_ci';
$db['default']['swap_pre'] = '';
$db['default']['autoinit'] = TRUE;
$db['default']['stricton'] = false;

I hope this tutorial helps you please don’t forget to give us your feedback in comments.

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Most Voted
Newest Oldest
Inline Feedbacks
View all comments