0

在我的

应用程序/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);

有用。有什么想法,请帮忙?

4

1 回答 1

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

于 2018-08-06T10:04:04.487 回答