本帖最后由 clearsky 于 2012-11-23 12:11 编辑
因为刚开始学习CI框架,也是自己摸索着来的,网上也没有找到合适的视频,所以就慢慢自己摸索这学习,不懂了看看手册。但是遇到下面的问题,完全没有找到那里错了。各位大虾帮忙解决!!
错误:
An Error Was EncounteredYour admin/config/database.php file does not appear to contain a valid configuration array. 前提:数据用户名与密码没有任何错误,不要纠结我的数据库密码是不是写错了。
贴出代码:
database.php中的配置
PHP复制代码
$active_group = 'default';
$active_record = TRUE;
$db['default']['hostname'] = "localhost";
$db['default']['username'] = "root";
$db['default']['password'] = "password";
$db['default']['database'] = "test";
$db['default']['dbdriver'] = "mysql";
$db['default']['dbprefix'] = "";
$db['default']['pconnect'] = TRUE;
$db['default']['db_debug'] = FALSE;
$db['default']['cache_on'] = FALSE;
$db['default']['cachedir'] = "";
$db['default']['char_set'] = "utf8";
$db['default']['dbcollat'] = 'utf8_general_ci';
$db['default']['swap_pre'] = "";
$db['default']['autoinit'] = TRUE;
$db['default']['stricton'] = FALSE;
$db['default']['port'] = "3306";
复制代码
然后就是Model中的代码
PHP复制代码
class Welcome extends CI_Model
{
public function __construct()
{
parent::__construct();
$this->load->database();
}
public function get_record()
{
$query = $this->db->get('ci_test');
return $query->result_array();
}
}
复制代码
控制器中的代码:
PHP复制代码
class Welcome extends CI_Controller
{
public function __construct ()
{
parent ::__construct ();
$this->load->model('welcome');
}
public function index ()
{
$data['test'] = $this->welcome->get_record();
var_dump($data['test']);
}
}
复制代码
然后我也在autoload.php中加载了database这个配置文件。 |