简体   繁体   中英

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.

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;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM