Jump to content

Advice on deleteing Msql data efficiantly


sonny

Recommended Posts

Hi

 

I have a cron Job that calls a php page that deletes old Msql data

every 5hrs or so

 

 

I have been thinking what would be the more efficient way to do this,

at the time of display or time of insertion, or just keep doing it via cron job?

 

I have a php page that displays data

 

$query=" SELECT * FROM visits WHERE page='$page' && vcode='1' ORDER BY id DESC LIMIT 20";
$result=mysql_query($query) or die(mysql_error());
while($row =mysql_fetch_array($result))

 

 

 

and another php page that inserts it

$queryup="UPDATE visits SET vcode='0' WHERE ip='$ip' && page='$page'";
$resultup=mysql_query($queryup) or die(mysql_error());

$query="INSERT INTO visits VALUES('NULL', '$ip', '$refer', '$page', '$flag', '$country', '$region', '$city', '$now', '1')";
$result=mysql_query($query) or die(mysql_error());

 

Looking for advice, on the most efficient and safest way to remove old data

 

Thanks

Sonny

Honestly it wouldn't make a difference as you are running a query to delete the data in both methods.  It all depends on how often you do it.

 

You are either running a query to remove more results once every couple hours or running multiple queries more often to remove less results.

 

I'd stick with the method you are already using, less queries = better performance

Archived

This topic is now archived and is closed to further replies.

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