killuagdt Posted July 19, 2010 Share Posted July 19, 2010 I am using PHP 5.3.2 with Mysql 5.1.47. I am wondering how can I delete MySql's rows after a 60 min? For example I have a table: Table Clientip UserIp Time (default current_timestamp) When an user go to the website, a row would be add (or update) to the table ClientIp. For example : 10.0.0.8 currrenttime I have a cronjob to run a script each minutes but I do not know how to check if an user's time value has exceeded 60 min and delete that user's data using mysql_query. So could you please tell me how to do so? Thank you very much for your help. Quote Link to comment https://forums.phpfreaks.com/topic/208135-delete-data-after-a-period-of-time/ Share on other sites More sharing options...
Kevin.Arvixe Posted July 19, 2010 Share Posted July 19, 2010 Setup a cronjob (in Linux) or scheduled task (in Windows) to run a cleanup script. This is the easiest way. Quote Link to comment https://forums.phpfreaks.com/topic/208135-delete-data-after-a-period-of-time/#findComment-1087974 Share on other sites More sharing options...
AbraCadaver Posted July 19, 2010 Share Posted July 19, 2010 Many tutorials on connecting to MySQL and running a query. Then: DELETE FROM `table_name` WHERE (UNIX_TIMESTAMP(`Time`) + 3600) > UNIX_TIMESTAMP() Quote Link to comment https://forums.phpfreaks.com/topic/208135-delete-data-after-a-period-of-time/#findComment-1087978 Share on other sites More sharing options...
inversesoft123 Posted July 19, 2010 Share Posted July 19, 2010 $timeto = 3600; $timenw = time(); $timeout = $timenw - $timeto; $exec = mysql_query("DELETE FROM table WHERE recordedtime<'".$timeout."'"); Quote Link to comment https://forums.phpfreaks.com/topic/208135-delete-data-after-a-period-of-time/#findComment-1087981 Share on other sites More sharing options...
AbraCadaver Posted July 19, 2010 Share Posted July 19, 2010 $timeto = 3600; $timenw = time(); $timeout = $timenw - $timeto; $exec = mysql_query("DELETE FROM table WHERE recordedtime<'".$timeout."'"); Except that MySQL stores CURRENT_TIME and all timestamps as YYYY-MM-DD HH:MM:SS, not a UNIX timestamp. Quote Link to comment https://forums.phpfreaks.com/topic/208135-delete-data-after-a-period-of-time/#findComment-1087987 Share on other sites More sharing options...
timvdalen Posted July 19, 2010 Share Posted July 19, 2010 Setup a cronjob (in Linux) or scheduled task (in Windows) to run a cleanup script. This is the easiest way. Many tutorials on connecting to MySQL and running a query. Then: DELETE FROM `table_name` WHERE (UNIX_TIMESTAMP(`Time`) + 3600) > UNIX_TIMESTAMP() Combine these two. Chances are you don't pay for your server and you don't have access to the cron system. Google something like free cron job system or something like that. Quote Link to comment https://forums.phpfreaks.com/topic/208135-delete-data-after-a-period-of-time/#findComment-1088030 Share on other sites More sharing options...
killuagdt Posted July 19, 2010 Author Share Posted July 19, 2010 Unix time really solves my problem easily. Thanks you all very much for your responses Quote Link to comment https://forums.phpfreaks.com/topic/208135-delete-data-after-a-period-of-time/#findComment-1088039 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.