Help with job creation agenda query

Asked

Viewed 23 times

0

Galley,

I’m making a script to trigger a message according to the record recorded in the database. It’s like a CRON task.

I have the following record inserir a descrição da imagem aqui

I will put a PHP page in the CRON task of Cpanel, but how can I make a query that checks every minute if the record is on time and day to be fired?

In this example of the image, you should return the record when: 9 hours 5 minute Monday, Tuesday or Thursday-made

See what month and day you are with *

SELECT * 
FROM  `agendamento` 
WHERE 1 =1
AND (mes = MONTH(NOW() ))

As I could check the asterisk and not enter the conditions, I will use OR operator will it work?

  • Do you want when in the record you have * (asterisk) in the month, it does not search? != '*'

  • Not only is this more complex as you need to check all fields. Minute, hour, day, week, month

  • Yes, then you should have one (AND) on the Where for each condition, one for minute, hour, day, week, ....

  • Example: If you are asterisk in the week field it means you must perform every day of the week, If you have Masterism in the MES field, it means you have to perform every month. If you are 1,3,5 in the DIA field it means that you should only perform on Monday, Wednesday and Friday

1 answer

0

SELECT *
FROM  agendamento
WHERE 1 =1
AND (
    (mes = MONTH(NOW())
    OR
    (mes = '*')
    )
AND (
    (dia = DAY(NOW())
    OR
    (dia = '*')
)

I believe this is the path that will be necessary to tread, although I think it will be much more interesting to have several Crons...

Browser other questions tagged

You are not signed in. Login or sign up in order to post.