Helpful Information
 
 
Category: Databases
CRON + Mysql / PHP3

Hi All,

I have a database that has to automatically on a daily basis check for certain things - add things to tables - and mail certain people according to results of the action. If one creates a PHP3 page to do these actions it works - but can those procedures be done by running a CRON job daily - would one run the .php3 page - or use some kind of MySQL command ?

Hope you can help.

Yep, you can use cronjobs to run shell or Perl scripts for daily/weekly/monthly maintenance. Sometimes I use a batch file/sql file pair to clean up stuff...

Example
##############
# file1.batch
##############
use db_name;

# clean out stuff older than two weeks and
# run once a day

delete from table_name where to_days(now()) - to_days(date_field) > 14;

##############
# file1.sql
##############
mysql -t -u username -ppassword < file1.batch

# no spaces between -p and password
# downside of this is that password is hard-
# coded into the file but its quick and dirty

Then run ./file1.sql from the command line or set up a cronjob to execute file1.sql whenever you want. Also works great with perl scripts, especially for MAIL functions, provided you have DBI set up and all that

Kyuzo

Nou ga aru taka wa tsume o kakusu










privacy (GDPR)