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 Link to comment https://forums.phpfreaks.com/topic/180442-time/ 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); Link to comment https://forums.phpfreaks.com/topic/180442-time/#findComment-952584 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.