0

I was wondering if there was an easy way of making a timer in a database with PHP , I want to make it so after 30 minutes of the row in the database being created, it gets deleted. Im sorry if this isnt specific enough but I cant see how I could put any more detail in this, feel free to comment so I can elaborate in any means necessary

2

1 Answer 1

2

You can make use of MySQL Events if you're on MySQL 5.1.6 or later.

Something along the lines of

CREATE EVENT purge_old_records
ON SCHEDULE EVERY 1 MINUTE
DO
   DELETE FROM table1 WHERE created_at <= NOW() - INTERVAL 30 MINUTE;

should do it.

Make sure that the event scheduler is enabled by using SHOW PROCESSLIST. If it's ON you should see a process "Daemon" by user "event_scheduler". Use SET GLOBAL event_scheduler = ON;to enable the scheduler if it's currently disabled. More on configuring the event scheduler read here.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.