基于$ curr_time->格式的SQL语句(' Y-m-d H:i')

时间:2012-08-29 13:53:25

标签: php mysql sql

为什么这段代码......

$curr_time = new DateTime();
$query_inprocess = "UPDATE `MyTable` 
                    SET inprocess=1 
                    WHERE startTime <= '" .$curr_time->format('Y-m-d H:i') . "'";

...导致SQL查询不正确,忽略<之后的语句?

UPDATE `MyTable` SET inprocess=1 WHERE startTime <

2 个答案:

答案 0 :(得分:1)

找到以下一个:

"UPDATE `MyTable` SET inprocess=1 WHERE startTime <= now()"

它可以帮助您获得所需的确切结果。

答案 1 :(得分:0)

试试这个

$curr_time = new DateTime();
$query_inprocess = "UPDATE `MyTable` 
                    SET inprocess=1 
                    WHERE startTime <='" .$curr_time->format('Y-m-d H:i'). "'";//OR use date('Y-m-d H:i') instead of $curr_time->format('Y-m-d H:i')