我有一个名为 pending
的字段,并被声明为 bool 值,默认值为 0
如下:
`pending` tinyint(1) NOT NULL DEFAULT '0'
我正在对数据库运行更新查询,以将 qpending
的状态更改为 1
,如下所示
$sql = "UPDATE `appointments` SET `pending` = '1' WHERE `appointments`.`id` = 124;
现在我的问题是,有没有办法通过采用条件子句(例如
)在 30 分钟后自动将pending
重新声明为 0
// After 30 Minutes of update!
if (!confirmed){
$sql = "UPDATE `appointments` SET `pending` = '0' WHERE `appointments`.`id` = 124;
}
表架构
CREATE TABLE IF NOT EXISTS `appointments` (
`id` int(6) NOT NULL AUTO_INCREMENT,
`date` varchar(100) CHARACTER SET utf8 NOT NULL,
`available` tinyint(1) NOT NULL DEFAULT '1',
`pending` tinyint(1) NOT NULL DEFAULT '0',
`confirmed` tinyint(1) NOT NULL DEFAULT '0',
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
最佳答案
你做错了。
使您的待处理字段不是 bool 值,而是日期时间,并包含到期时间的值。然后在您的选择查询中只需将该值与当前时间进行比较。所以而不是
SELECT * FROM appointments WHERE pending = 1
只要做到
SELECT * FROM appointments WHERE pending < NOW()
这个解决方案要么更简单,要么更灵活
关于php - 如何在 MySQL 上运行及时自动查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42199668/