CI框架模型中常见的数据库操作

来源:互联网 发布:4g网络dns劫持 编辑:程序博客网 时间:2024/05/22 07:07
整理的一些常见的数据库操作,很有用。

emptyclass Blog_model extends CI_Model {    public $title;    public $content;    public $date;    public function get_last_ten_entries()    {        $query = $this->db->get('entries', 10);        return $query->result();    }    public function insert_entry()    {        $this->title    = $_POST['title']; // please read the below note        $this->content  = $_POST['content'];        $this->date = time();        $this->db->insert('entries', $this);    }    public function update_entry()    {        $this->title    = $_POST['title'];        $this->content  = $_POST['content'];        $this->date = time();        $this->db->update('entries', $this, array('id' => $_POST['id']));    }}