Reputation: 3238
How does it work?
// Purge obsolete login attempts
$this->db->or_where('UNIX_TIMESTAMP(time) <', time() - $expire_period);
$this->db->or_where is codeigniter method,both 'UNIX_TIMESTAMP' and time() return timestamp, I can't figure out why 'UNIX_TIMESTAMP' will less than the 2nd argument.
Upvotes: 0
Views: 50
Reputation: 4674
I have no understanding of Codeigniter framework. But the UNIX_TIMESTAMP()
part is an SQL function to fetch or parse a date as Unix timestamps. You may check it on MySQL Date and Time Function documentation.
So the UNIX_TIMESTAMP(time)
is actually fetching the time
column on the table and parse it into Unix timestamps.
In conclusion, the above code will fetch all rows with the time
column less than the current time - $expired_period
.
Upvotes: 0
Reputation: 20737
time
is a field in your database (most likely a datetime field) which is being converted to Unix timestamp format by your DB. So in theory it would be equivalent to writing this:
$this->db->or_where('time <', date('Y-m-d H:i:s', (time() - $expire_period)));
Upvotes: 1