在我的
application / config / config.php
我有这个自定义配置项
$config['roles_permissions_db'] = 'roles_permissions';
并且我正在尝试使用
连接到数据库$CI =& get_instance();
$CI->load->database($CI->config->item('roles_permissions_db'),TRUE);
并且我已经为'roles_permissions'建立了数据库连接,也建立了数据库配置(application / config / database.php)
$db['roles_permissions']['hostname'] = "localhost";
$db['roles_permissions']['username'] = "root";
$db['roles_permissions']['password'] = "";
$db['roles_permissions']['database'] = "roles_permissions";
但每次我跑步时,都会引发此错误
您尚未指定数据库连接
但如果我这样做,
$CI->load->database('roles_permissions',TRUE);
有效。有什么想法,请帮忙吗?
答案 0 :(得分:0)
希望下面能对您有所帮助。...
$db['default'] = array(
'dsn' => '',
'hostname' => 'localhost',
'username' => 'root',
'password' => '',
'database' => 'database_name',
'dbdriver' => 'mysqli',
'dbprefix' => '',
'pconnect' => TRUE,
'db_debug' => TRUE,
'cache_on' => FALSE,
'cachedir' => '',
'char_set' => 'utf8',
'dbcollat' => 'utf8_general_ci',
'swap_pre' => '',
'encrypt' => FALSE,
'compress' => FALSE,
'stricton' => FALSE,
'failover' => array()
);
请参考以下文档以获取有关数据库连接的更多详细信息。 https://www.codeigniter.com/userguide3/database/connecting.html