0

I have a table in SQL Server. Its data is about call details of Cisco IP-Phones. I have a script in PHP. The data of this table updates whenever a new call occurred. Once the table updated, I want to fetch new data. How can I know when the table is updated? It is not in certain time and depends on when a new call is made.

Fields of table are:

1. id
2. WaitingTime(This is the value that I needed)
3. dateTime (It is the date and the time of updating and inserting the new value)

1 Answers1

0

Technically you could write an ON INSERT trigger that could call a PHP script. However, it's not recommended. There is more information regarding this here: Calling a php file by using mysql trigger

A better approach might be to simply run your PHP script in a cron job to poll the database and process any new calls.

Community
  • 1
  • 1
Luke Cordingley
  • 665
  • 4
  • 11
  • 1
    I would agree that a cron job would be a better approach. And polling it every minute or an interval of your choice. As a suggestion you might want to create new column "processed" that is a tinyint value to mark the status of that row, with a value of 1 being processed and 0 for unprocessed – Newbi3 Feb 19 '14 at 07:47
  • 1
    Initially all the data will have a "processed" status of 0 and once the row is processed set the value to 1, so that your cron job script will only grab new rows of unprocessed records. – Newbi3 Feb 19 '14 at 07:50
  • This is made a high load on server –  Feb 19 '14 at 08:00
  • @DiariB The answer really depends on how soon and how important is the data. If you want less of a server load, maybe choose a higher interval such as every 3 or 15 minutes for the cron job. – Newbi3 Feb 19 '14 at 08:10
  • @Luke Cordingley's suggestion of the `ON INSERT` MySQL trigger is also a good solution that would be based around MySQL. However, then you'd have to read the database with PHP. What are you trying to accomplish? Are you trying to just collect analytics and call duration? – Newbi3 Feb 19 '14 at 08:14