简体   繁体   中英

php and mysql procedure that runs once per month

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?

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?

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.

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 ;

Set up a cronjob that points to a PHP file containing a call to your SQL query.

http://en.wikipedia.org/wiki/Cron

you could use cronjobs to fix this :).

greets, stefan

CRON JOB is the solution for this. Tuts here .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM