Question NEED HELP?
#1

Hey Members,

I want to ask a simple question

Is that possible to delete a account in MySQL after a certain time and how i can do that??

Thanks
Reply
#2

you mean inactive players account?

Edit: you can use these codes,

Quote:
Originally Posted by BroZeus
Посмотреть сообщение
It is done in php so as to avoid lag while looping through all players in mysql and removing odl accounts
Based on what In0cent told this is the php script that will remove old accounts
Код HTML:
<?php
$dbservername = "127.0.0.1";//change
$dbusername = "root";//change
$dbpassword = "";//change
$dbname = "DB_Name";//change

$con = mysql_connect($dbservername, $dbusername, $dbpassword);

if(!con)exit();
$now = strtotime("now");

mysql_select_db($dbname, $con);

$query = "SELECT * FROM players"; //------here name of table

$result = mysql_query($query) or die(mysql_error());

while($row = mysql_fetch_array($result))
{
switch($row["lastonmonth"])//---------here the name  column which stores last month
{
case 1: 
$mon = "January";
break;
case 2:
$mon = "February";
break;
case 3:
$mon = "March";
break;
case 4:
$mon = "April";
break;
case 5:
$mon = "May";
break;
case 6:
$mon = "June";
break;
case 7:
$mon = "July";
break;
case 8:
$mon = "August";
break;
case 9:
$mon = "September";
break;
case 10:
$mon = "October";
break;
case 11:
$mon = "November";
break;
case 12:
$mon = "December";
break;
}
$ld = $row["lastondate"];//---------here the name  column which stores last date
$ly = $row["lastonyear"];//---------here the name  column which stores last year
$last = strtotime("$ld $mon $ly");
$dif = $now - $last;
if($dif < (60 * 60 * 24 * 30 * 4))continue;//4 months
$nn = $row["username"];//-----------------------------------here the name of column storing player name
mysql_query("DELETE  players WHERE username='$nn'");//--------here name of table and also the column name which stores player name
}
mysql_close($con);
?>

*The code removes accounts that have been not used in last 4 monts || if u want to change duration then go to line in which i have commented "//4 monts" and in that line change 4 to whatever month u want

I have commented in front of lines which needs changes in them like table name change , column name change , you need to change them according to your table.

To auto remove all of the old acconts this script needs to be run every 12 hours
Well u wont run it by urself after every 12 hours

So to run this script every 12 hours by it self, settings need to be made in the host on which the script is hosted
An example of showing how to auto run php script after every specified time is in this video --
https://www.youtube.com/watch?v=l5Wa8sgbo2Y

In the following video it is shown how to run a file named WP-Mail.php after a specified interval of time..

If the website host u use doesn't provide this facility then u need to find which does.
Reply
#3

How i am gonna use this code ? and where i have to put that code?
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)