我有一个使用CodeIgniter框架的项目。在模型类中,我尝试从数据库加载数据,但浏览器返回一个非常非常奇怪的结果。页面返回如下:
load->database('demo', TRUE);}function getData(){...}
(and follow are very much signs like China character +_+)
下面是user_model.php的内容:
class User_model extends CI_Model
{
function __construct()
{
parent::__construct();
#Line 6: $CI =& get_instance();
$this->load->database('demo', TRUE);
}
function getData()
{
$query = $this->db->query("select * from user");
if ($query->num_rows() < 0)
show_error('Database is empty!');
else
return $query->result();
}
}
我搜索了很多,得到了一些解决方案,但没有一个能解决我的问题。
我试图重写构造函数(使用$CI和重写下一行$CI->load->database('demo', TRUE))
我尝试使用$db作为私有变量,分配$this->$db = $this->load->database('demo', TRUE)…
请帮帮我,我已经为此损失了2天。我无法解释汉字是如何在那里显示的。我都快疯了。
p/s:我的环境:windows XP SP3/WAMP服务器2.1/CodeIgniter 2.0.2所有配置完成,系统可以顺利运行欢迎信息
如果您的代码在浏览器中可见,在我看来,脚本只是输出而不是执行。如果其他php脚本运行良好,您可能忘记在user_model.php中打开<?php
标记。
class User_model extends CI_Model
{
function __construct()
{
parent::__construct();
#Line 6: $CI =& get_instance();
$DB1 = $this->load->database('demo', TRUE);
}
function getData()
{
$query = $DB1->query("select * from user");
if ($query->num_rows() < 0)
show_error('Database is empty!');
else
return $query->result();
}
}