I'm new to php. I want to execute mysql query periodically (say every 5 seconds) using script. Query can be anything (as for now such as getting all data one by one from databse or inserting data to database). How can I do this? I've been through some examples but as I'm new to php, I'm not getting.
Asked
Active
Viewed 991 times
0
-
ajax, cron job. How the query result is handled? – vaibhavmande Oct 23 '13 at 04:59
-
you can create event in mysql database check this link http://dev.mysql.com/doc/refman/5.1/en/create-event.html :) – Pragnesh Chauhan Oct 23 '13 at 05:02
-
@vaibhavmande: is there any other way to execute query except using ajax? – thumber nirmal Oct 23 '13 at 05:27
-
@thumbernirmal depends on what do you want to do with the query result. Can you explain what are you trying to achieve? – vaibhavmande Oct 23 '13 at 05:30
2 Answers
1
you can do this using event or cron job created on server
using event
DELIMITER $$
ALTER EVENT `ev_myevent` ON SCHEDULE EVERY 5 SECOND STARTS '2013-10-23 11:00:00' ON COMPLETION PRESERVE ENABLE DO BEGIN
// your code here
END$$
DELIMITER ;
using cronjob
check this link
1 Cronjob execute PHP script

Community
- 1
- 1

Pragnesh Chauhan
- 8,363
- 9
- 42
- 53
0
If you want to update content in your site every 5 seconds and update database then you do it by ajax calling. Other then if you want to update database periodically then use cron.

SKG
- 510
- 4
- 20