自动删除旧数据

I have a table in which I would like the old data to be deleted automatically if the time is older than 5 days. The table looks like this : http://de.share-your-photo.com/e6508ee7a6. Can someone help me? The below Code does not work

<?php
require_once __DIR__ . '/connection.php';
$variants_remove='DELETE FROM drucker AS drucker WHERE datediff(now(), drucker.zeit) > 5';
$req = $dbConnect->query($variants_remove);
?>

Change to

WHERE drucker.zeit) < NOW() - INTERVAL 5 DAY

You could use CURDATE() instead of NOW() if you prefer to backup from midnight this morning.

You need to write script as same as you have written, and set it on cron. Data will be deleted automatically

You can use crontab if your on linux/debain/etc..

open your terminal and type

$ crontab -e

this will let you edit all crwonjobs
and the terminal will output something like this:

Crontab edit

Then you can add a new Cron like this after all # ... lines:

$ 1 2 3 4 5 /path/to/your/autodelete.php

for explanaiton:

1: Minute (0-59)
2: Hours (0-23)
3: Day (0-31)
4: Month (0-12 [12 == December])
5: Day of the week(0-7 [7 or 0 == sunday])
/path/to/command – Script or command name to schedule

if you dont want to use hours and day for example then write a * instead of an Int

$ 50 * * 6 2 /path/to/your/autodelete.php


You can read all here