首页 > 解决方案 > DELETE Record from database after 10 seconds of insertion of record

问题描述

I want to delete the record from table after 10 seconds of insertion. Basically I am sending data from my python script to PHP server and storing it into database. Below is my MySQL query but it is not working i don't know why? any help would be appreciated Thank you.

$sql5= "DELETE FROM data1 WHERE creation_time >(NOW()- INTERVAL 10 SECOND)";
    $res = $conn->query($sql5);

Note: Here creation_time is my column which contains time and date of insertion of data.

标签: phpmysql

解决方案


try below, I think it needs to less than, (if you want to delete records that are more than 10 seconds old)

// sql to delete a record
$sql = "DELETE FROM data1 WHERE DATE(creation_time) < NOW() - INTERVAL 10 SECOND";

if ($conn->query($sql) === TRUE) {
  echo "Record deleted successfully";
} else {
  echo "Error deleting record: " . $conn->error;
}

推荐阅读