php - 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;
}
推荐阅读
- uipath-studio - 将 UI-Path 工作室与代理网络一起使用
- css - 无法获得“垂直对齐:中间;” 在标题中工作
- node.js - 如何在 Nest js 中使用 fastify-adapter 配置速率限制
- python - 如何在熊猫中拉伸列长度的值?
- excel - 我是 VBA 新手,无法在新工作表上正确写入数据
- typescript - 打字稿映射接口
- xamarin - 找不到类型或命名空间 IUIWindowSceneDelegate、UIScene、UISceneSession、UISceneConnectionOptions
- reactjs - 使用 redux 发送错误不起作用
- c# - 从电子邮件中获取 AD 组名称
- c# - 配置为空