问题描述
我需要在午夜自动重置MySQL字段值.它是表中特定行中的特定列.我知道如何在PHP中执行此操作,但我不知道如何在午夜执行PHP脚本,而不必亲自进行操作.您有可行的解决方案吗?
I need to reset a MySQL Field value automatically at midnight. It is a specific column in a specific row in a table. I know how to do this in PHP but I do not know how to execute the PHP Script at midnight without someone having to do it themselves. Do you have any viable solutions?
--------------------最好不要使用Cron Jobs.
--------------------Preferably without using Cron Jobs.
推荐答案
如果您在Linux上运行,则可以使用 cronjob
If you are running on linux you would use a cronjob
在大多数发行版中,都有一个名为crontab的命令可以为您安排任务和所需的特定格式:
On most distros there is a command called crontab that schedules tasks for you and a specific format you need:
0 0 * * * php /path/to/file.php
在编辑您的:p之前先写下来,不知道还有其他方法.您是否有特定理由不使用cronjob?
Wrote this before you edited yours :p I'm not sure there is any other way. Do you have a specific reason not to use a cronjob?
如果php文件被标记为可执行文件,则可能甚至不需要指定php部分.
You may not even need to specify the php part if the php file is marked as executable i.e
0 0 * * * /path/to/file.php
只需从Linux命令行执行"chmod + x/path/to/file.php"
Just do "chmod +x /path/to/file.php" form the linux command line
这篇关于在不执行用户的情况下重置MySQL字段值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!