unidox Posted November 5, 2009 Share Posted November 5, 2009 I have a cron that runs every 5 min, that adds information about my server into a db. I have a graph that graphs the last 6 hours (360 min). How do I have the cron remove any expired data from the database? (Greater than 30 min ago.). Any help appreciated. Thanks Quote Link to comment Share on other sites More sharing options...
huszi001 Posted November 6, 2009 Share Posted November 6, 2009 If you store timestamps its realy easy. $user ="mysql username"; $pass ="mysql password"; $dbhost ="mysql server address"; $dbname ="mysql db name"; $link = mysql_connect($dbhost, $user, $pass); if (!$link) { die('Could not connect: ' . mysql_error()); } $db_selected = mysql_select_db($dbname, $link); if (!$db_selected) { die ('Can\'t use ".$dbname." : ' . mysql_error()); } $expire_time = time()-1800; /get time and - 30min * 60sec $query = "DELETE FROM `table name` WHERE `time row` < ".$expire_time; $result = mysql_query($query); Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.