我的代码是这样的:
function insert_delete()
{
...
$hotel = $hotel;
$address = $address;
$created_date = date('Y/m/d H:i:s');
$data = array('hotel' => $hotel,
'address' => $address,
'created_date' => $created_date
);
$this->db->insert('tb_hotel',$data);
$query = "DELETE FROM tbl_hotel WHERE created_date='$created_date'";
$this->db>query($query);
}
调用insert_delete函数时,它将运行insert查询和删除查询。
插入数据时如何做,是直接删除数据,但半小时后删除数据?
谢谢
答案 0 :(得分:1)
我希望你不要在半小时后想要删除实际运行,所以我假设您希望删除整理任何超过30分钟的行。
public function insert_delete()
{
...
$hotel = $hotel;
$address = $address;
$created_date = date('Y/m/d H:i:s');
$data = array('hotel' => $hotel,
'address' => $address,
'created_date' => $created_date
);
$this->db->insert('tb_hotel',$data);
// delete old rows more than 30 minutes old
$date = new DateTime($created_date);
$date->sub(new DateInterval('PT30M'));
$del_dt = $date->format('Y-m-d H:i:s');
$query = "DELETE FROM tbl_hotel WHERE created_date < '$del_dt'";
$this->db>query($query);
}