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

Php 每年使用cron作业更新数据库,php,mysql,Php,Mysql,我想在php项目中使用cron作业更新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 ['stu

我想在php项目中使用cron作业更新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);
 }
$stud=“select*from student\u class where class使用此选项可帮助您在服务器上添加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
使用此选项可以帮助您在服务器上添加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 cli以便从终端运行脚本。在脚本中,php二进制文件的位置应位于标题中,例如#/usr/bin/php 让脚本在终端环境中工作


然后按照Philippe的建议编辑crontab。

安装php cli,以便您可以从终端运行脚本。在脚本中,php二进制文件的位置应该在标题中,例如#/usr/bin/php 让脚本在终端环境中工作

然后按照Philippe的建议编辑crontab