Clearing Out Old Survivors.

R.J.

New Member
Anyone have a simple script to clear out survivors that are 6 -8 weeks old? I have about 2000+ dead accounts. Perhaps something based on the last updated column?
 
In your SQL:

PHP:
DELETE FROM survivor WHERE last_updated < now() - INTERVAL 6 WEEK
Or create a cronjob if you have a webserver, and make it run every day or every second day.
For cronjob, link to a PHP file with this content:
PHP:
<?php
 
    $link = mysql_connect('YOURDBHOST', 'YOURDBUSER', 'YOURDBPASS');
    if (!$link) die('Could not connect: ');
    mysql_select_db('YOURDBNAME', $link);
    $delete = mysql_query("DELETE FROM survivor WHERE last_updated < now() - INTERVAL 6 WEEK");
    if (!$delete) echo "Error";
 
?>
 
In your SQL:

PHP:
DELETE FROM survivor WHERE last_updated < now() - INTERVAL 6 WEEK

You should use SUBDATE() I believe,

For bliss
PHP:
DELETE FROM survivor WHERE last_updated < SUBDATE(now(),  INTERVAL 6 WEEK)

For pwn
PHP:
DELETE FROM character_data WHERE LastLogin < SUBDATE(now(),  INTERVAL 6 WEEK)

If you are using pwn, however, I recommend creating a new column with a datestamp that saves current_datestamp when an UPDATE is executed on the row. For this, just "Design Table" in Navicat and create a new column - let's call it LastUpdate. Now give the column a type of Timestamp and check the box that says "on Update Current_timestamp".
This just means that data will update to the current time whenever anything is changed. This is more reliable than LastLogin as you do not run the risk of deleting any characters in use if LastLogin has malfunctioned.

You can then use

PHP:
DELETE FROM character_data WHERE LastUpdate < SUBDATE(now(),  INTERVAL 6 WEEK);

There is no need to use a PHP cron job. Just include that piece of code in whatever SQL function/procedure you execute on restart for maintenance. If you don't know/haven't made on - just put it at the bottom of pCleanup.
 
Back
Top