整理的一些常见的数据库操作,很有用。
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']));
}
}
常用数据库操作总结
本文总结了常见的数据库操作,包括获取最近十条记录、插入记录及更新记录等实用功能。通过具体的PHP示例代码展示了如何实现这些操作。

1223

被折叠的 条评论
为什么被折叠?



