Effectively notify when MySQL data entry changes

拜拜、爱过 提交于 2019-12-12 02:59:20

问题


I've been using an HTTP POST to a php file to change entries in a given MySQL database. Essentially, the second the value changes, I would like the user that is viewing the database table to be notified. For now my temporary solution is to auto refresh a page displaying the table to keep it updated but I feel like there has to be a more efficient way of going about this.


回答1:


Do you really have to update it in the same second? It looks like a server killer feature.
Read about Comet, maybe it will be useful.




回答2:


IIRC mysql_affected_rows() will only report instances where the data has changed (i.e. if you try to update a row to its current values then it won't give an error).

I find it hard to believe that you've got someone watching a screen waiting for an update to occur - maybe a better approach would be to add a timestamp field to the record - but note that if you do this, and in the absence of other checks, the record will always update - to prevent make sure at least one of the fields has changed in the update.

C.




回答3:


When I had to do this, I created a one-row table containing the last time any relevant part of the database was updated. Then the once-per-second activity was confined to seeing if the contents of that one-row table showed newer than the local value; if so, refresh.

The one-row table could be updated via triggers from any table containing relevant facts, or from the application, as you think best.




回答4:


checkout pines notify i use it with ajax submitted changes



来源:https://stackoverflow.com/questions/3131326/effectively-notify-when-mysql-data-entry-changes

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!