我尝试查询模型,但它给出了错误。如果我将查询放在控制器中,它工作正常。这是我的控制器(Home.php):
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Home extends CI_Controller {
function __construct()
{
parent::__construct();
$this->load->helper('form');
$this->load->helper('asset');
$this->load->database();
$this->load->library('table');
}
public function index()
{
$this->load->model('News');
$resultNews = $this->News->queryNews();
$data['resultNews'] = $resultNews;
$this->load->view('front/index',$data);
}
}
/* End of file welcome.php */
/* Location: ./application/controllers/welcome.php */
这是我的模型(News.php):
<?php
if( !defined('BASEPATH')) exit('No direct script access allowed');
class News extends CI_Model {
function __construct(){
parent::__construct();
$this->load->database();
}
function queryNews(){
$this->db->query("SELECT * FROM `news` WHERE news_show_date >= CURDATE() ORDER BY news_show_date DESC LIMIT 0 , 2");
$query = $this->db->get();
return $query;
}
}
/* End of file welcome.php */
/* Location: ./application/controllers/welcome.php */
?>
然后它吐出一个错误:
A Database Error Occurred
Error Number: 1096
No tables used
SELECT *
Filename: C:\AppServ\www\hijet\system\database\DB_driver.php
Line Number: 330
我是否在做错事而我错过了它?