时间过去后如何删除mysql行? [英] How to delete mysql row after time passes?

查看:25
本文介绍了时间过去后如何删除mysql行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不知道从哪里开始:

我有一个存储 postIDDate 的数据库.

I have a database that stores postID and Date.

我想要做的是让我的网站自动删除 Date 小于今天的所有行.这个脚本根本不能有任何用户输入.没有按钮点击,什么都没有.该脚本必须每天在午夜运行.

What I want to do is have my website auto delete all rows where Date is less than today. This script can't have any user input at all. No button clicks, nothing. The script must run every day at midnight.

我一直在到处寻找能做到这一点的东西,但一无所获.

I've been looking all over the place for something that does this and I've found absolutely nothing.

推荐答案

您可以使用 PHP 脚本并在您的 cpanel 上使用 cron 作业.

You can use PHP script and use cron job on your cpanel.

示例:

cronjobcommand.php

cronjobcommand.php

<?php 
 include 'your_db_connection';
 mysql_query("DELETE FROM your_table_name WHERE Date < NOW()");
?>

我在下面附上了截图供您参考.

I have attached a screenshot below for your more reference.

这篇关于时间过去后如何删除mysql行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆