doudengshen5591 2014-06-20 20:31
浏览 28
已采纳

当今日期与截止日期匹配时,MySQL会触发

I'm developing an application in CakePHP 2.4.7

I have my MySQL database and I've come to the necessity of triggering an update when the system's date and hour matches a due date I have in a table.

The table I'm using is the following

CREATE TABLE applied_surveys (id CHAR(36) NOT NULL PRIMARY KEY,
                        display_name VARCHAR(200),
                        area_id CHAR(36) NOT NULL,
                        survey_id CHAR(36) NOT NULL,
                        system_user_id CHAR(36) NOT NULL,
                        code VARCHAR(50),
                        init_date DATE,
                        due_date DATE,
                        init_hour TIME,
                        due_hour TIME,
                        completed INT,
                        state TINYINT DEFAULT 1,
                        max_responders INT,
                        created DATE, modified DATE,
                        FOREIGN KEY (area_id) REFERENCES areas(id),
                        FOREIGN KEY (survey_id) REFERENCES surveys(id),
                        FOREIGN KEY (system_user_id) REFERENCES system_users(id));

As you can see, I'm using an init date/hour and a due date/hour. My intention here is that I add a survey and I set a due date. When the due date and hour are reached the system must change my status(state) value to 0, meaning that the survey has been closed.

I'm integrating this database to a CakePHP application, but I'm not really sure where I should program the logic for this situation.

  • 写回答

3条回答 默认 最新

  • dougezhua0017 2014-06-20 20:39
    关注

    You can't write "sistem", it's system.

    You will need to run a cron job every second/minute/hour, or whatever you prefer, that would check each record and see which ones are later than the system date. You can't expect it to run exactly at the time the dates become exactly the same, especially if you account for the seconds.

    You can read about CRON jobs here : http://code.tutsplus.com/tutorials/managing-cron-jobs-with-php--net-19428

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥20 java在应用程序里获取不到扬声器设备
  • ¥15 echarts动画效果的问题,请帮我添加一个动画。不要机器人回答。
  • ¥60 许可证msc licensing软件报错显示已有相同版本软件,但是下一步显示无法读取日志目录。
  • ¥15 Attention is all you need 的代码运行
  • ¥15 一个服务器已经有一个系统了如果用usb再装一个系统,原来的系统会被覆盖掉吗
  • ¥15 使用esm_msa1_t12_100M_UR50S蛋白质语言模型进行零样本预测时,终端显示出了sequence handled的进度条,但是并不出结果就自动终止回到命令提示行了是怎么回事:
  • ¥15 前置放大电路与功率放大电路相连放大倍数出现问题
  • ¥30 关于<main>标签页面跳转的问题
  • ¥80 部署运行web自动化项目
  • ¥15 腾讯云如何建立同一个项目中物模型之间的联系