javascript MySQL 表更改的事件侦听器?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/20748071/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-27 19:12:30  来源:igfitidea点击:

Event listener for MySQL table change?

javascriptphpmysqlajaxhttp

提问by Andrew

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.

是否有 php/javascript/mysql/ajax 事件侦听器或方法可以在每次 MySQL 表中的数据更改时调用函数 - 例如添加新行或更改/删除行时。

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

还是我从错误的角度看它,我还在学习 AJAX。

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

只是想指向正确的方向,我什么也找不到。谢谢。

EditBasically 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.

编辑基本上当用户坐在我的网站上时,如果新数据从另一个来源添加到服务器上的数据库中(不是因为该用户的操作),我希望能够调用一个函数来异步加载该新数据该用户的数据。

采纳答案by Mike Brant

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

如果您尝试根据 MySQL 中的其他更改更改 MySQL 中的日期,触发器应该可以工作:

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

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.

如果您希望在 MySQL 中的数据更改时具有服务器端或客户端回调,那么您将无法通过 MySQL 本身获得这种能力。您可能需要向架构中添加一些内容(标志、时间戳等),以指示数据何时更改并运行异步过程以根据数据更改执行某些操作。

回答by underscore

For that you need to use MySql Proxy

为此,您需要使用MySql 代理

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

MySQL Proxy 是一个简单的程序,它位于您的客户端和 MySQL 服务器之间
,可以监视、分析或转换它们的通信。它的灵活性允许多种用途,包括负载平衡;故障转移;查询分析;查询过滤和修改;还有很多。安装和构建说明位于源存档中

Or you need to Maintain a log

或者你需要维护一个日志

回答by psuhas

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

您可以使用以下处理来自 MySQL DB 的每个或选定更改的事件

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

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