Code:
<?php
class clean extends MySQLi
{
//private $connected = false;
public function __construct($host, $user, $pw, $db)
{
parent::__construct($host, $user, $pw, $db);
if(mysqli_connect_error())
die("Connection Error #".mysqli_connect_errno());
//$this->connected = true;
return true;
}
public function __destruct()
{
//if($this->connected)
if($thread = $this->thread_id)
{
$this->kill($thread);
$this->close();
}
return true;
}
function getPlayers($days = 30)
{
$query = $this->query("SELECT `players`.`id` FROM `players` WHERE `players`.`lastlogin` <= ".(time() - $days * 24 * 3600).";");
$players = array();
if($query->rowCount())
while($f = $query->fetch())
$players[] = $f[0];
return $players;
}
function getAccounts()
{
$query = $this->query("SELECT `accounts`.`id` FROM `accounts` WHERE `accounts`.`id` NOT IN(SELECT `players`.`account_id` FROM `players`);");
$accounts = array();
if($query->rowCount())
while($f = $query->fetch())
$accounts[] = $f[0];
return $accounts;
}
function deletePlayers($players)
{
if(!$players)
return false;
$query = "DELETE FROM `players` WHERE `players`.`id` = '{$players[0]}'";
if(count($players) > 1)
for($i = 1; $i < count($players); $i++)
$query .= " OR `players`.`id` = '{$players[$i]}'";
$this->query($query.";");
return true;
}
function deleteAccounts($accounts)
{
if(!$accounts)
return false;
$query = "DELETE FROM `accounts` WHERE `accounts`.`id` = '{$accounts[0]}'";
if(count($accounts) > 1)
for($i = 1; $i < count($accounts); $i++)
$query .= " OR `accounts`.`id` = '{$accounts[$i]}'";
$this->query($query.";");
return true;
}
}
$clean = new clean("host", "user", "pw", "db");
$players = $clean->getPlayers();
$accounts = $clean->getAccounts();
if($players)
{
echo count($players)." players<br />\n";
$clean->deletePlayers($players);
}
if($accounts)
{
echo count($accounts)." accounts<br />\n";
$clean->deleteAccounts($accounts);
}
unset($clean);
?>
NOTE: It's untested and I have no clue if it works, if you dont know how to use it, you don't deserve to have it.