I'm writing a utility for work using forms, then submitting the supplied information into a database with php. The work this intended for is to be performed every thirty days. I need to find a way to automatically check the database and be sure each table in this database has had an entry within the last 30 days or email me if not. Any help you all might give would be greatly appreciated.

Member Avatar for diafol

If you want an automatic check, use CRON JOBS - see your host for this as they don't always supply this facility. Else, get a script to email you every time the db is updated. If it's just a simple mail, the php mail() function should be fine.

If the db is updated a number of times every month, the emails will become tedious, so I would use CRON JOBS in this case. You'll still need to write a script for the cron job. Something like:

[your php script]
1. check the tables for the latest entry/update
2. use the php date function and the mysql date_format function to just check the numerical month or something more sophisticated (e.g. last 30 days)
3. if no records are returned for a table, note it.
4. collate the info and mail it via mail().

If you produce a script I'll have a look at it and advise further.

yea, definately a cron job would be your best bet. If youre hosting on a cPanel server, you can do this without going to the command line. If not, and you'll either need to get your host to set up the job for you, or if you have ssh, you can create the cron job yourself.

Still stuck here. I understand how to make most of this work, and yes thankfully I do have Cron. The part that's getting me is this, each of my tables have a field for timestamp. I can search and pull the most recently timestamped record. However, finding a way to have my script compare this timestamp with the current time and date is the problem.

Member Avatar for diafol

Check out the INTERVAL keyword in the MySQL online manual.

Looks as though I got it working thanks for your help. The whole thing seems to be working perfectly, so far.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.