【问题标题】:CodeIgniter local database connection issueCodeIgniter 本地数据库连接问题
【发布时间】:2017-08-02 17:51:15
【问题描述】:

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

您在 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());

【问题讨论】:

  • 你的 phpmyadmin 中是否有任何名称为 ci_test 的数据库?
  • 请分享错误信息

标签: php html codeigniter


【解决方案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);

试试这个。祝你好运。

【讨论】:

  • 我刚刚尝试过,但它给出了同样的错误。
  • 检查您的数据库是否正确?如果存在,请在 config/autoload.php 中检查。检查这个 $autoload['libraries'] = array('database');你必须添加数据库库。
【解决方案2】:

此错误与连接组有关,与数据库名称无关。你在那里指定的连接组是default,如第一行所示:$db['default']

寻找:

$active_group = 'ci_test';

替换为:

$active_group = 'default';

codeigniter documentation有更多信息。

【讨论】:

    【解决方案3】:

    您可以尝试这个解决方案来解决您的问题。

    $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
    );
    

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-04-04
      • 2016-05-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-01-13
      • 1970-01-01
      相关资源
      最近更新 更多