mysql expire after?
- Started
- Last post
- 6 Responses
- jpea
could anyone point me in the right direction for making rows in a mysql db expire and delete themselves after a set date?
php script to figure out the date, or can it be done directly in mysql?
- lebowski0
a) if you can't do this then you shouldn't be near mysql
b) see above
- jpea0
so much for learning
asswipe.
anyone?
- acescence0
1. get the curr date and set a var that is curr date minus your desired "age"
2. DELETE from table WHERE DATE < your "age"
- jpea0
so it is with php and not an actual mysql expire function.
thanks :)
- ldww0
you could do it with a stored sql query.. but you would need cron to fire it off anyway, so might as well do php.
- nospacebar0
An alternative to this would be to add the time of insertion, and when selecting those rows, have a time limit for what it returns.
For 30 days:
SELECT * FROM table WHERE WHERE date_column > DATE_SUB(CURDATE(),INTERVAL 30 DAY);More here:http://dev.mysql.com/doc/re...