Jump to content

Eliminate MySQL Entry based on date


inquisitive

Recommended Posts

Alright here is what I am trying to do

 

I have a website where users login and submit items for sale...

 

I approve them and then their item goes into a list on the index.php page of items for sale...

 

Now I was stupid and didn't program a way to delete them and there are tons of entries now...

 

In order to remedy this situation I would like to program a script that eliminates the entries in the database after they have been in the database for 2 weeks...anyone have any idea how to do this????

Link to comment
https://forums.phpfreaks.com/topic/120880-eliminate-mysql-entry-based-on-date/
Share on other sites

If you're using mysql 5.0 or above and want to clean the records automaticaly, you can use something like this:

To enable the event scheduler:

SET GLOBAL event_scheduler = 1;

To trigger to stored procedure every 60 minutes:

CREATE EVENT clean
ON SCHEDULE EVERY 60 MINUTE
COMMENT 'Clean old data.'
DO CALL cleandata();

To run the clean-up command:

DELIMITER $$

DROP PROCEDURE IF EXISTS `cleandata` $$
CREATE PROCEDURE `cleandata`()
BEGIN

DELETE FROM entry_table WHERE entry_date < CURDATE() - INTERVAL 2 WEEK;

END $$

DELIMITER ;

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.