开发者

Delete records that is greater than time()

I'm trying to delete records that has expired after 20 minutes, the column contains a timestamp which is time()+1200 (20 minutes forward).

When I execute this query:

$sql = "DELETE FROM " . SESSIONS_TABLE . "
        WHERE session_expire >= " . time() . "
        AND session_open = 1";

All of the records that has not passed the timestamp still get开发者_运维技巧 deleted... how come it's doing this?


You probably want to delete records that are less than time().


Your WHERE condition is incorrect. You need to use..

WHERE session_expire <= " . time() . "

...otherwise, you're deleting sessions that are set to expire after the time provided.

Additionally, you could simply use MySQLs NOW function, if your database server's clock is in the same timezone, etc.

i.e.:

WHERE session_expire <= NOW()
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜