Gowri
Gowri

Reputation: 16835

Can a MySQL query be run every second?

I like to update my table every second. I know this is possible in AJAX but is this possible in MySQL query? I found MySQL event, can I get solution from this?

Upvotes: 0

Views: 3292

Answers (4)

Vijay
Vijay

Reputation: 5433

If you could actually tell a bit more about this situation and why u need this to be done, it will help us to give a better solutions.

With assumptions on what you are trying to achieve , we can give the best.

Anyway sending too many ajax and updating query every second is not an good option.

Here is an idea,

if you can store the expiry time for each row and you can set them set status to 1 where your condition matches.

Anyway i think there must be some reason to change the status to 1 (may be for making them not to display/consider).. If we know the exact reason, i think i can give a better solution..

Upvotes: 0

flipcupninja
flipcupninja

Reputation: 53

so cron is a scheduler in linux to run anything periodically. So let's say your script that contains "**if date_time > now() ** then update status as 1" is called updateIfOld.php then you should make crontab runs "php updateIfOld.php" every second. Here are the manuals to use crontab: http://www.manpagez.com/man/5/crontab/Ta3HK4KosQPd8aT8BQ&usg=AFQjCNErp1Hz19N7xJwVY1wisQNxmtgpQQ&sig2=D4NQu19AJnBZil9J54V8ww

Upvotes: 0

keithwill
keithwill

Reputation: 2044

It is possible to write an sql query that will set an update status equal to 1 when the date value for that record is out of date, however you will still need a scheduled task to run this sql query from time to time.

If you are able to run code on your server, then you should write up a script that periodically runs your query against the database.

Upvotes: 0

bensiu
bensiu

Reputation: 25564

" i wanna check condition **if date_time > now() ** then update status as 1 . is this possible"

it does not seems like you need special status to be setup...

this condition can be checked when data is pulled (if need to be marked execute UPDATE and SELECT when pull),

also it can be done as cron job every minute (not sure can be done every second), however if it very related with user being on page - ajax could be the way to do it and downgrade performance at this same time

Upvotes: 1

Related Questions