首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >CodeIgniter本地数据库连接问题

问CodeIgniter本地数据库连接问题
EN

Stack Overflow用户
提问于 2017-08-02 17:51:15
回答 3查看 1.7K关注 0票数 0

我尝试过这样做来建立本地数据库连接。但是它给出了这样的错误:

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

代码语言:javascript
复制
$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());
EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2017-08-02 17:56:55

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

寻找:

代码语言:javascript
复制
$active_group = 'ci_test';

代之以:

代码语言:javascript
复制
$active_group = 'default';

代码点火器文档中有更多的信息。

票数 0
EN

Stack Overflow用户

发布于 2017-08-02 18:06:26

代码语言:javascript
复制
$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
EN

Stack Overflow用户

发布于 2017-08-02 17:58:24

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

代码语言:javascript
复制
$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
);

希望这能帮到你。谢谢!

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/45467791

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档