Reputation: 6955
I have a php built website with a mysql database.
I need an sql function to run once per every month.
How would i go about doing this?
EDIT
Really sorry for not making it clear. I don't have a linux VPS. Just a basic hosting service with php and mysql capabilities. I am looking into purchasing a "real" server in the future but for now, are there any onther methods?
Upvotes: 1
Views: 800
Reputation: 76537
Everyone seems to want you to use a cronjob.
Problem with that is that is requires superuser access to the server.
I would suggest using a MySQL event instead.
Note that this does require superuser access in the MySQL database.
See: http://dev.mysql.com/doc/refman/5.1/en/events.html
First make sure the event scheduler is enabled:
SET GLOBAL event_scheduler = ON;
You can set up an event as follows:
DELIMITER $$
CREATE EVENT IF NOT EXISTS event_name ON SCHEDULE EVERY MONTH
STARTS CURRENT_TIMESTAMP + INTERVAL 1 DAY
ON COMPLETION PRESERVE
ENABLE
COMMENT 'comment'
DO BEGIN
//SQL statements here.
END $$
DELIMITER ;
Upvotes: 5
Reputation: 17434
Set up a cronjob that points to a PHP file containing a call to your SQL query.
http://en.wikipedia.org/wiki/Cron
Upvotes: 2
Reputation: 27313
If you have proper access to the server, I would set a CRON job.
Most of the modern distribution have a folder /etc/cron.monthly
, you can put your script there and it will be run each month.
If you want more control when the script is ran, you can setup your own CRON entry.
Upvotes: 3