CodeIgniter本地数据库连接问题

时间:2017-08-02 17:51:16

标签: php html codeigniter

我试过这个来建立本地数据库连接。但它给出了这个错误:

  

您在config / database.php文件中指定了无效的数据库连接组(ci_test)。

$db['default'] = array(
    'dsn'   => '',
    'hostname' => 'localhost',  // pass this
    'username' => 'root',  // pass this
    'password' => '',  // pass this
    'database' => 'ci_test',  // pass this
    '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());

3 个答案:

答案 0 :(得分:1)

$active_group = 'default';
$query_builder = TRUE;


$db['default'] = array(

'dsn'   => '',
'hostname' => 'localhost', //this will be same
'username' => 'root',  //replace with your username
'password' => '',       //replace with your password
'database' => 'test',   //replace with your database name which you want to use
'dbdriver' => 'mysqli',
'dbprefix' => '',
'pconnect' => FALSE,
'db_debug' => (ENVIRONMENT !== 'production'),
'cache_on' => FALSE,
'cachedir' => '',
'char_set' => 'utf8',
'dbcollat' => 'utf8_general_ci',
'swap_pre' => '',
'encrypt' => FALSE,
'compress' => FALSE,
'stricton' => FALSE,
'failover' => array(),
'save_queries' => TRUE);

试试这个。祝你好运。

答案 1 :(得分:0)

此错误与连接组有关,而与数据库名称无关。您在其中指定的连接组为default,如第一行所示:$db['default']

寻找:

$active_group = 'ci_test';

将其替换为:

$active_group = 'default';

codeigniter documentation中有更多信息。

答案 2 :(得分:0)

您可以针对您的问题尝试此解决方案。

$active_group = 'default';
$query_builder = TRUE;

$db['default'] = array(
    'dsn'   => '',
    'hostname' => 'localhost',
    'username' => 'root',
    'password' => 'root',
    'database' => 'ci_test',
    'dbdriver' => 'mysqli',
    'dbprefix' => '',
    'pconnect' => FALSE,
    'db_debug' => (ENVIRONMENT !== 'production'),
    'cache_on' => FALSE,
    'cachedir' => '',
    'char_set' => 'utf8',
    'dbcollat' => 'utf8_general_ci',
    'swap_pre' => '',
    'encrypt' => FALSE,
    'compress' => FALSE,
    'stricton' => FALSE,
    'failover' => array(),
    'save_queries' => TRUE
);

我希望这会对你有所帮助。谢谢!

相关问题