php - 如果数据库发生变化,自动刷新内容

标签 php mysql database

当 mysql 数据库表发生变化时,如何在不刷新页面本身的情况下自动将数据库行 (PHP) 的值添加到页面?

所以,有点像这样:Automatically refresh browser in response to file system changes? , 但是当数据库发生变化时,不是用文件系统的变化来刷新浏览器,而是更新内容,而不刷新任何东西。

谢谢。我已尝试尽可能清楚地说明这一点。

最佳答案

Please note this is outdated answer. Recent ways of doing that is: websockets, server-send events. Nice example of that is Firebase. You can find simple code example in: https://github.com/laithshadeed/wsk-feedback. In this example you will see that updating firebase will send event to the browser via websocket, then the UI will update.

这称为 Comet/Reverse Ajax/HTTP 服务器推送 http://en.wikipedia.org/wiki/Comet_(programming) .有许多技术可以做到这一点,还有许多现有框架可以为您做到这一点。

关于 Comet https://stackoverflow.com/search?q=comet SO 中有很多答案

简单的实现是使用 javascript setTimeout 和 setInterval 来检查服务器状态,在 mysql 上使用触发器/存储过程。

深入探索 Comet。有两本关于此的好书:

Comet and Reverse Ajax 2008 By Dave Crane

Comet and Reverse Ajax Cover Image

Chapter 4 (River of Content) - Building the Realtime User Experience 2010 By Ted Roden

Building the Realtime User Experience Cover image

Update: You may look to the newer techniques in HTML5 like Websockets and Server-sent Events, although IE does not support them well, at the moment Server-sent events is not supported in IE and Web Sockets only supported in IE10

关于php - 如果数据库发生变化,自动刷新内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8100594/

相关文章:

mysqld : dial tcp 127. 0.0.1:3306: 连接:连接被拒绝

mysql - 如何执行从不同表返回唯一值的 mySQL 查询

sql - 如何在 SQLite 中搜索子字符串?

php - 我想在存储日期 20 天后自动更新我的 sql 表数据

mysql - 保持数据与异步 HTTP 请求一致

php - 如何检查特定文件是否在 php 项目和 linux 环境中使用

使用客户端凭据(X.509 证书)的 PHP Azure Active Directory API 访问

php - facebook live search 使用 php jquery mysql,显示 5 个结果如何显示其余的?

php - 如何制作一个 if 语句来检查一个变量是否在 mysql 数据库中

PHP MySQL 过滤相关内容中的内容值