Lavanya ks
Lavanya ks

Reputation: 31

Deleting records from the server after 15 days

I need to delete uploaded files from the server after 15 days using SQL.

How would I do that? The following is the current code, but it isn't working.

<?php
$con = mysql_connect("localhost","mt","mt");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("mt", $con);

function curdate(){
date_default_timezone_set ("Asia/Calcutta"); 
$cd=date("d/m/Y");
}

mysql_query("DELETE FROM mt_upload WHERE DateTime < DATE_SUB(curdate(), INTERVAL 1 DAY)
'");

mysql_close($con);
?> 

Upvotes: 0

Views: 417

Answers (2)

Eric
Eric

Reputation: 330

I believe there may be a date / datetime mismatch in your statement which I've seen act goofy under MySQL. Try to match date comparison with dates and datetime comparisons with datetime.

Try using now() instead of curdate() and see if you get better behavior.

"DELETE FROM mt_upload WHERE DateTime < DATE_SUB(now(), INTERVAL 15 DAY)"

Upvotes: 1

Ankit Sachan
Ankit Sachan

Reputation: 7840

You have to configure cron jobs for that........

you have cron Job in your cpanel setup that.......

configure the timestamps,

set the php file with only delete script no timestamp management.........

may be you can search for CRon job over google......

Upvotes: 0

Related Questions