Run a mySQL query as a cron job?
I personally find it easier use MySQL event scheduler than cron.
Enable it with
SET GLOBAL event_scheduler = ON;
and create an event like this:
CREATE EVENT name_of_eventON SCHEDULE EVERY 1 DAYSTARTS '2014-01-18 00:00:00'DODELETE FROM tbl_message WHERE DATEDIFF( NOW( ) , timestamp ) >=7;
and that's it.
Read more about the syntax here and here is more general information about it.
It depends on what runs cron on your system, but all you have to do to run a php script from cron is to do call the location of the php installation followed by the script location. An example with crontab running every hour:
# crontab -e00 * * * * /usr/local/bin/php /home/path/script.php
On my system, I don't even have to put the path to the php installation:
00 * * * * php /home/path/script.php
On another note, you should not be using mysql extension because it is deprecated, unless you are using an older installation of php. Read here for a comparison.