I need to remove mysql records that have been made half a hour (or more) ago. That is, leave only the records of the last 30 minutes. This every time a certain php script runs. How do I?
I need to remove mysql records that have been made half a hour (or more) ago. That is, leave only the records of the last 30 minutes. This every time a certain php script runs. How do I?
DELETE FROM nometabela
WHERE campodatahorainsercao < DATE_SUB(NOW(), INTERVAL 30 MINUTE)
Note the following:
Everything that you have in the table that was inserted more than 30 minutes ago will be deleted.
All records with a date less than the execution date will be deleted - 30 minutes. That is, only the most recent ones who have not yet completed 30 minutes will remain.
Well, since you do not have many details I'm going to imagine you have a user table, this table has constant inserts all day.
In the user you would have, login, password, registeredEm, UltimaAlteraco
All you have to do is delete a date based on the registered date, passing as a parameter a Date object half an hour before
Assuming that they are 20/01/2017 20:00:00 in point
You run the script made in PHP
then just do
delete from user where registeredEm > 01/20/2017 19:30:00
Based on the current time that is 20/01/2017 20:00:00 o'clock I sent as a parameter half an hour before they are 20/01/2017 19:30:00
Delete to all records "registered" above 20/01/2017 19:30:00
All "registered" users that are greater than 01/20/2017 19:30:00 will be deleted. In other words everything that was registered in the 30 minute period will be deleted.