Jamie Wheeler
Jamie Wheeler

Reputation: 35

creating a Cron Job to delete rows in mysql database when they are early than today

I have tried many times now but i just dont seem to be able to crack it!

I have set up a cron job on cpanel (was every minute for testing) with the command set at

/php cronjobcommand.php

In my cronjobcommand file i have the following code

<?php//conenct to your DB
$db_conn = mysql_connect('localhost', 'xxxxx', 'xxxxx');
mysql_select_db('xxxxx', $db_conn);


$result = mysql_query("DELETE FROM 'data' 
  WHERE 'offerends' < CURDATE()}
                               LIMIT 1", $db_conn);
    //might want to check here to see if the query executed successfully

?>

I want it to delete any rows that have a date of less than today at midnight each night. what am I doing wrong? The job seems to find my file fine, i get my email without errors, but no difference to database.

Thanks Jamie.

Upvotes: 1

Views: 2004

Answers (1)

Jake N
Jake N

Reputation: 10583

Run this against your database using Adminer or PHPMyAdmin

SELECT * FROM 'data' WHERE 'offerends' < CURDATE() LIMIT 1

This will give you the matching rows, you can then debug using this query which might be easier.

You also seem to have a stray } in your DELETE query.

Upvotes: 4

Related Questions