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()
精彩评论