schneider04 发表于 2012-11-11 23:55:34

求助 接连DB一起过不去

错误信息:
Fatal error:Call to a member function database() on a non-object in D:\xampp\htdocs\test_php100.com\ci_offer\app_offer\models\GoodsInfo_M.php on line 8

源码:
model:
<?php
class GoodsInfo_M extends CI_Model{
public function __construct(){
parent ::__construct();
$this->load->database();
}
public function GetMyResult(){
$sql = "select * from goods_info";
$query = $this->db->query($sql);   
$result = $query->result();   
return $result;
}
}

controller:
class GoodsInfo_C extends CI_Controller {

public function __construct(){
parent::__construct();
}
public function index(){

$this->load->model('GoodsInfo_M','GoodsInfo_M',true);
$result = $this->GoodsInfo_M->GetMyResult();
if($result){
   $data['temp'] = "kdkd";
}
$this->load->view('ShowInfo', $data);
}

VIEW:
<p><?php echo $temp; ?></p>
<table class="">
<thead>
<tr>
</tr>
</thead>
<tbody>
<?php foreach ($res as $item):?>
<tr>
   <td><?php echo $item; ?></td>
</tr>
<?php endforeach;?>
</tbody>
</table>

注:database配置文件,用户名等验证测试正常。未启用自动载入DATABASE。

schneider04 发表于 2012-11-12 00:05:59

版本为2.1.3

jlxu1101 发表于 2012-11-13 12:07:47

静候大神出现,我也不知道有什么错

Hex 发表于 2012-11-16 13:00:08

代码看起来没问题。
你的文件名命名和放置路径是不是正确?
页: [1]
查看完整版本: 求助 接连DB一起过不去