-5

I need to create a simple automatic daily function to set my database columns to 0.

I know how to do with UPDATE using mysql query.

I need to know how set an automatic function without using refresh, Java or other. I don't want to refresh page every xx seconds/min/h. I need this function to start at 8 am.

This because i need to change all my customers column and set to 0 daily access.

I'm using php, html and a mysql database. Same story with a 1ST day month cron. I need to reset all to 0 every 1st day of each month (automatically).

I want to use this cron also for activate my web page only from 10 am to 3pm, don't ask me why, i'm doing examples.

I already read other topic but i don't know how write code for cron, i m a beginner. I found this: 00 08 * * 1 php --q directory/cron.php Maybe it runs every MONDAY something.... right... but how can i set my function to start all every day using *** ok but please explain me how to run functions and where i should write them.

halfer
  • 19,824
  • 17
  • 99
  • 186
  • look up 'mysql event scheduler', try it out, then come back with a question if you can't get it to work – pala_ May 07 '15 at 00:52
  • 1
    There are already lots of example about this issue. Search first, and then ask if not found. – ihsan May 07 '15 at 00:52
  • How to set up a cron job depends on what hosting you are using. If you have access to the console (e.g. via SSH), use `crontab -e`, and if you are on shared hosting, it is likely to be set up in a control panel. – halfer May 07 '15 at 06:23

1 Answers1

2

Don't use a cron if you do not require any data processing or function handling. If you are simply updating your database on a schedule, use MySQL events.

Here is the documentation on ensuring that MySQL event scheduling is on: 19.4.2 Event Scheduler Configuration

Here is the documentation on creating events: 13.1.11 CREATE EVENT Syntax

Example of what you're asking it to do daily at 8am:

CREATE EVENT do_things
  ON SCHEDULE
   EVERY 1 DAY
   STARTS (TIMESTAMP(CURRENT_DATE) + INTERVAL 1 DAY + INTERVAL 8 HOUR)
     DO
     UPDATE *update query to make your reset happen goes here*

You can use this as a start and modify it as needed based on the information in the CREATE EVENTS documentation.

Patrick Lyver
  • 389
  • 2
  • 7
  • ok now i will check this for mysql... what should i do for activate my web page only from 10 to 12 am? This because i have a input there, it MUST works only from 10 to 12 am – Marco Taraddei May 07 '15 at 10:17
  • @MarcoTaraddei create a php function that checks the time and only shows your input during the window you want – Patrick Lyver May 07 '15 at 18:26