CodeIgniter默认使用MySQL。笔者在实际开发中选择的数据库是PostgreSQL(如果大家开发新的项目,强烈推荐大家使用)。按照CodeIgniter的文档需要配置applcation/config/database.php文件:
$active_group = 'default';
$active_record = TRUE;
$db['default']['hostname'] = 'localhost';
$db['default']['username'] = 'postgres';
$db['default']['password'] = 'root';
$db['default']['database'] = 'db_any';
$db['default']['dbdriver'] = 'postgre';
$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;
$db['default']['port'] = 5432;
请大家一定不要忘记红色的一句,默认这句是没有的。会导致不能正确连接PostgreSQL。