我试图在我当地的机器上运行CodeIgniter,但是我收到了这个错误
有谁知道这是什么问题?我在Mac上使用MAMP
ErrorException [致命错误]:无法使用提供的设置连接到数据库服务器。 / Filename:core / Loader.php /行号: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)
先谢谢!
这是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;
添加了环境
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.');
}
}
答案 0 :(得分:0)
您需要设置默认数据库。例如
$active_group = 'development';
或
$active_group = 'staging';