First create the PHP script to connect to the database and empty the table
("DELETE FROM table;") as if you were going to visit the page manually every
time you wanted to empty the table. This shouldn't be too hard:

// EmptyTable.php
$dbLink = mysql_connect("host","user","pass");
mysql_query("DELETE FROM table");

Once you have that working (test it by visiting the page and then checking
to see if it emptied the table), now you want to get cron to run that script
on a certain schedule. There are two ways to do this.

#1 -----------------------------------
If your host has the command-line/CGI version of PHP installed, you can
simply have cron run:
/path/to/php /path/to/EmptyTable.php. It would more realistically look like:

/usr/local/bin/php /home/myaccount/EmptyTable.php

#2 -----------------------------------
If #1 doesn't work (you don't have the CGI version installed), you can have
another 3rd-party program "request" the page. For instance, most Linux
systems have a utility called wget which retrieves web pages and files by

You can have cron run that command to simulate a visit to that page, which
effectively runs the script and the table gets emptied:

- Jonathan

-----Original Message-----
From: Jennifer Downey [mailto:[EMAIL PROTECTED]]
Sent: Thursday, March 28, 2002 11:32 AM
Subject: [PHP-DB] MySQL, PHPand cron

Hi all,

Wondering if anyone might know how to empty a table with a php script and
cron job?
Would someone point me to a tutorial or help with this?


PHP Database Mailing List (
To unsubscribe, visit:

PHP Database Mailing List (
To unsubscribe, visit:

Reply via email to