设置现有CodeIgniter的数据库连接错误

时间:2014-10-01 20:13:54

标签: php mysql database codeigniter mysqli

我从服务器下载了CodeIgniter项目,我想在我的localhost中运行它,运行时出错了。有谁知道这是什么问题?我在Mac上使用了MAMP。

这是我的db错误:

  

ErrorException [致命错误]:无法使用提供的设置连接到数据库服务器。 / Filename:core / Loader.php /行号:346

这是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;

2 个答案:

答案 0 :(得分:0)

您根本没有连接到MySQL服务器。请确保您的计算机上安装了MySQL。其次,检查MySQL服务是否正在运行。第三,确保您在Database.php文件中填写的访问信息。

答案 1 :(得分:0)

没有冒犯,但仅仅因为我的好奇心是你的数据库位于同一台服务器上?我看到你使用&#39; localhost&#39;但数据库也可能在不同的机器上。我会使用终端仔细检查用户/密码(从提示中使用MySQL,连接,使用&#39; bmgr&#39;,从表中选择)。如果这有效,则表示您的文件未正确编辑。如果它没有指向错误的机器和/或您有防火墙问题和/或用户权限问题