Event listener for MySQL table change?

2019-04-26 11:45发布

Is there a php/javascript/mysql/ajax event listener or method that can call a function each time the data in a MySQL table changes - such as when a new row is added, or a row changes/is deleted.

Or am I looking at it from the wrong perspective, I'm still learning AJAX.

Just looking to be pointed in the right direction, I couldn't find anything. Thanks.

Edit Basically when a user is sitting on my site, if new data is added to the database on the server from another source (not because of an action of this user), I want to be able to call a function to asynchronously load that new data for this user.

3条回答
倾城 Initia
2楼-- · 2019-04-26 12:25

If you are trying to change date in MySQL based on other changes in MySQL, triggers should work:

http://dev.mysql.com/doc/refman/5.6/en/triggers.html

If you are looking to have server-side or client-side callbacks when data in MySQL changes, then you won't have that ability via MySQL itself. You would likely need to add something to your schema (flags, timestamps, etc.) that indicate when data is changed and run asynchronous process to do something based on the change in data.

查看更多
我只想做你的唯一
3楼-- · 2019-04-26 12:41

For that you need to use MySql Proxy

MySQL Proxy is a simple program that sits between your client and MySQL server(s)
that can monitor, analyze or transform their communication. Its flexibility allows for a wide variety of uses, including load balancing; failover; query analysis; query filtering and modification; and many more. Installation and build instructions are in the source archive

Or you need to Maintain a log

查看更多
Viruses.
4楼-- · 2019-04-26 12:48

You can use following which processes events upon each or selected changes coming from MySQL DB

https://github.com/spencerlambert/mysql-events

查看更多
登录 后发表回答