Re: Periodically delete old records from mysql table

From: Date: Tue, 27 May 2008 13:35:28 +0000
Subject: Re: Periodically delete old records from mysql table
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-274725@lists.php.net to get a copy of this message
At 1:26 PM +0200 5/27/08, Stefano Esposito wrote:
Hi all, i'm wandering if there's some intelligent way to delete old records from a mysql table without using cronjobs (i can't), using PHP. This table has a field which stores the value returned from time(), and i want to do mysql_query("DELETE FROM table WHERE time<='".(time()-86400)."'"); at periodical intervals (say every 15 hours). Thanks for any hint :) Ciao, Stefano
Stefano: I can't help your wandering around, but if you are wondering about how to periodically delete records from a dB without using a cron, then this will work. Create and set a field for "last_deletion" to current time. When users accesses the dB, then have the process check current time with "last_deletion" and if the "last_deletion" is greater than current time plus 15 hours, then run the "delete old records" routine and reset the "last_deletion" to current time. That way, users accessing the dB will trigger the "delete old records" process. Cheers, tedd -- ------- http://sperling.com http://ancientstones.com http://earthstones.com

« previous php.general (#274725) next »