本文介绍了mysqli :: real_connect():(HY000/1049):codeigniter中的未知数据库错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是Codeigniter PHP框架的新手.在测试我的应用程序时,出现未知数据库db_name"错误.我已经浏览了几个站点,但是没有找到解决问题的方法,因为我正试图用它连接wamp的mysql数据库.任何帮助都将是可观的.

I'm new to Codeigniter PHP framework. When I'm testing my application I get 'Unknown database db_name' error. I have browsed through several sites but didn't found solution for the problem as I'm trying the same to connect with wamp's mysql database. Any help would be appreciable.

以下是配置文件夹中的database.php:描述测试的图片数据库:

Following is database.php in config folder: image describing Test database:

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

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

推荐答案

我在安装新的wampserver 3.2.0时遇到了相同的错误,默认情况下会安装MariaDB并将端口3306分配给它,这是很邪恶的,您不能甚至改变它.我认为codeigniter/php默认会尝试连接到此端口.我使用了following,它对我有用,即主机名=>'localhost:3308'

I was getting same error when i installed new wampserver 3.2.0, it is an evil it installs MariaDB by default and port 3306 is assigned to it , you cannot even change it. I think codeigniter/php tries to connect to this port by default.I used following , it worked for me i.e. hostname => 'localhost:3308'

 $db['default'] = array(
        'dsn'   => '',
        'hostname' => 'localhost:3308',
        'username' => 'root',
        'password' => '',
        'database' => 'soft',
        '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
    );

这篇关于mysqli :: real_connect():(HY000/1049):codeigniter中的未知数据库错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-28 14:31