gpt4 book ai didi

php - 15分钟后删除记录

转载 作者:行者123 更新时间:2023-11-29 01:13:42 25 4
gpt4 key购买 nike

我有一个不活动的系统。它应该在 15 分钟后从非事件表中删除用户。如果在该表中找不到用户,我还有一个代码可以将用户注销。非事件脚本会在每次页面刷新时更新用户。

这是我试过的非事件代码,到目前为止它不起作用:

$result = mysqli_query($con,"SELECT * FROM inactive");

while($row = mysqli_fetch_array($result))

if ($row['inactive'] > timestampadd(MINUTE, -15, now()))
{



}else {

$db_query = "DELETE FROM inactive WHERE username='$username'";
$result = mysql_query($db_query);


}

最佳答案

CREATE EVENT IF NOT EXISTS `remove_inactives`
ON SCHEDULE EVERY 15 MINUTE
ON COMPLETION PRESERVE
ENABLE
DO
DELETE FROM `inactive`
WHERE `timestamp` < DATE_SUB(NOW(), INTERVAL 15 MINUTE)
;

^ 使用一组并忘记重复出现 MySQL Event .让服务器为您完成工作:)

对于 PHP:

mysqli_query($connection, // or mysql_query(
<<<SQL
CREATE EVENT IF NOT EXISTS `remove_inactives`
ON SCHEDULE EVERY 15 MINUTE
ON COMPLETION PRESERVE
ENABLE
DO
DELETE FROM `inactive`
WHERE `timestamp` < DATE_SUB(NOW(), INTERVAL 15 MINUTE)
;
SQL;
); // ends *_query() call

您只需运行一次即可在服务器上安装!

关于php - 15分钟后删除记录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17631363/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com