dongwen7380 2014-09-30 23:07
浏览 81

CodeIgniter中的数据库连接错误

I tried to run CodeIgniter in my local machin,but I got this error

does anyone know what is the problem? I ma using MAMP on mac

ErrorException [ Fatal Error ]: Unable to connect to your database server using the provided settings. / Filename: core/Loader.php / Line Number: 346 APPPATH/controllers/home.php [ 9 ]

protected $os_platforms = NULL;

function __construct()
{
    parent::__construct();
    $this->load->model(strtolower(__CLASS__).'_model', 'model');
    $this->load->config('brandmgr', TRUE);

    $this->lang->load(strtolower(__CLASS__));
    $this->_auto_rootCrumb();
FCPATH/system/database/DB_driver.php [ 1197 ] » MY_Exceptions->show_error(arguments)
FCPATH/system/database/DB_driver.php [ 124 ] » CI_DB_driver->display_error(arguments)
FCPATH/system/database/DB.php [ 148 ] » CI_DB_driver->initialize()
FCPATH/system/core/Loader.php [ 346 ] » DB(arguments)
FCPATH/system/core/Loader.php [ 1171 ] » CI_Loader->database()
FCPATH/system/core/Loader.php [ 152 ] » CI_Loader->_ci_autoloader()
FCPATH/system/core/Controller.php [ 51 ] » CI_Loader->initialize()
APPPATH/core/MY_Controller.php [ 25 ] » CI_Controller->__construct()
APPPATH/controllers/home.php [ 9 ] » MY_Controller->__construct()
FCPATH/system/core/CodeIgniter.php [ 308 ] » Home->__construct()
FCPATH/index.php [ 214 ] » require_once(arguments)

Thanks in advanced!

Here is database.php

<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');

$active_group = ENVIRONMENT;
$active_record = TRUE;

$db['development']['hostname'] = 'localhost';
$db['development']['username'] = 'fake';
$db['development']['password'] = 'fake';
$db['development']['database'] = 'bmgr';
$db['development']['dbdriver'] = 'mysqli';
$db['development']['dbprefix'] = '';
$db['development']['pconnect'] = TRUE;
$db['development']['db_debug'] = TRUE;
$db['development']['cache_on'] = FALSE;
$db['development']['cachedir'] = '';
$db['development']['char_set'] = 'utf8';
$db['development']['dbcollat'] = 'utf8_general_ci';
$db['development']['swap_pre'] = '';
$db['development']['autoinit'] = TRUE;
$db['development']['stricton'] = FALSE;

$db['staging']['hostname'] = 'localhost';
$db['staging']['username'] = 'fake';
$db['staging']['password'] = 'fake';
$db['staging']['database'] = 'bmgr1';
$db['staging']['dbdriver'] = 'mysqli';
$db['staging']['dbprefix'] = '';
$db['staging']['pconnect'] = TRUE;
$db['staging']['db_debug'] = TRUE;
$db['staging']['cache_on'] = FALSE;
$db['staging']['cachedir'] = '';
$db['staging']['char_set'] = 'utf8';
$db['staging']['dbcollat'] = 'utf8_general_ci';
$db['staging']['swap_pre'] = '';
$db['staging']['autoinit'] = TRUE;
$db['staging']['stricton'] = FALSE;

added the enviroment

define('ENVIRONMENT', 'development');

 *---------------------------------------------------------------
 * ERROR REPORTING
 *---------------------------------------------------------------


if (defined('ENVIRONMENT'))
{
switch (ENVIRONMENT)
{
    case 'development':
    case 'staging':
        error_reporting(E_ALL);
     ini_set('display_errors', 1);
    break;
    case 'testing':
    case 'production':
        error_reporting(0);
     ini_set('display_errors', 0);
    break;

    default:
        exit('The application environment is not set correctly.');
}
}
  • 写回答

1条回答 默认 最新

  • dongyejun1983 2014-10-01 01:34
    关注

    You need to set a default database. for example

    $active_group = 'development';
    

    or

    $active_group = 'staging';
    
    评论

报告相同问题?

悬赏问题

  • ¥15 为什么使用javacv转封装rtsp为rtmp时出现如下问题:[h264 @ 000000004faf7500]no frame?
  • ¥15 乘性高斯噪声在深度学习网络中的应用
  • ¥15 运筹学排序问题中的在线排序
  • ¥15 关于docker部署flink集成hadoop的yarn,请教个问题 flink启动yarn-session.sh连不上hadoop,这个整了好几天一直不行,求帮忙看一下怎么解决
  • ¥30 求一段fortran代码用IVF编译运行的结果
  • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
  • ¥15 C++ 头文件/宏冲突问题解决
  • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
  • ¥50 安卓adb backup备份子用户应用数据失败
  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛