在我的中
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);
它是有效的。有什么想法吗?
我希望下面能帮助你。。。。
$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