gpt4 book ai didi

php - 每年使用 cron 作业更新数据库

转载 作者:太空宇宙 更新时间:2023-11-03 12:30:00 24 4
gpt4 key购买 nike

我想在 php 项目中使用 cron job 更新 mysql 数据库。下面是我想每年运行的一段代码。我曾尝试在 mysql 中使用事件调度程序,但我失败了。

$stud="select * from student_class where class<4";
while ($row=mysql_fetch_array($stud))
{
$sql = "INSERT into student class(id,student_id,class,year) values('','{$row
['student_id']}','{$row['class']}','{$row['year']}+1')" ;
mysql_query($sql);
}

谁能帮忙?

最佳答案

使用这个 documentation帮助您在服务器上添加 cron 作业

crontab -e
1 2 3 4 5 php /path/to/php_file arg1 arg2

地点:

1: Minute (0-59)
2: Hours (0-23)
3: Day (0-31)
4: Month (0-12 [12 == December])
5: Day of the week(0-7 [7 or 0 == sunday])
/path/to/php_file- Script or command name to schedule

所以您的 cron 作业看起来像这样在每年 1 月 1 日的 00:00 执行:

0 0 1 1 * php /path/to/php_file arg1 arg2

关于php - 每年使用 cron 作业更新数据库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15907163/

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