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

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/php_225869/article/details/73163397
整理的一些常见的数据库操作,很有用。

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']));
    }

}

猜你喜欢

转载自blog.csdn.net/php_225869/article/details/73163397