I have the following php code set to run as a CRON job. It runs once a day and never returns an error so I assume it is running properly. The problem is, the rows aren’t being deleted from my database!
I’ve tested the php and the variables work. I’ve tested my query and that works too so I’m at a loss…
<?php
$isCLI = ( php_sapi_name() == 'cgi-fcgi' );
if (!$isCLI)
die("cannot run! sapi_name is ".php_sapi_name());
exit;
//Connect to DB
mysql_connect("xxxxxx.com", "xxxxxxxxxx", "xxxxxxxxxxxx") or die(mysql_error());
mysql_select_db("xxxxxxxxxxx") or die(mysql_error());
//Get today's date
$todayis = date("Y-m-d");
$todayis = strtotime(date("Y-m-d", strtotime($todayis)) . " -4 hours");
$todayis = date('Y-m-d', $todayis);
//Delete rows in userContests where reminder is less than or equal to today's date
mysql_query("DELETE FROM userContests WHERE reminder <= '$todayis';") or die(mysql_error());
?>
Can someone explain to me why the rows won’t delete?
If that is the whole script, I would say you have forgotten to connect to the database.
Edit: This seems to be the problem:
That translates to:
So basically you always stop your script on the 6th line, nothing after that will ever be executed.