Jump to content

Time


unidox

Recommended Posts

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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.