我们如何使用 php 检测数据库表中的更新或插入?

发布于 2024-12-19 18:02:10 字数 204 浏览 3 评论 0原文

数据库表已被人员 A 更新为 status_id、status_text、timedate 等(如 facebook 状态)。另一个人B评论了该状态,A和B都在线。 A 将如何收到通知(就像在 Facebook 中一样)。意思是我们如何才能知道数据库表的变化。任何方式都可以通过女巫表触发数据库外部(像 facebook 那样的通知)。 任何解决方案或线索将不胜感激。

A database table's been updated by a person A with status_id,status_text,timedate etc (like facebook status). Another person B comments on that status, Both persons A and B are online. How would person A will be notified(like in facebook). Means how can we know the change in database table. any way through witch table trigger out side the database(Notification like in facebook).
Any solution or clue will be appreciated.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

_失温 2024-12-26 18:02:10

1)将数据库操作封装在一个自己的类中,并提供相应的方法,这样您就可以完全控制数据库操作。当您调用添加评论的方法时,您还可以在同一方法中添加通知。
2) 您可以将通知保存在自己的数据库中,并通过页面重新加载来显示它们。您甚至可以更进一步,对服务器进行轮询以仅通过 AJAX 呈现特定部分。

1) Wrap database operations in an own class with corresponding methods, then you have full control over the database operations. When you call the method to add a comment, you can also add a notification in the same method.
2) You can save notifications in an own database and show them by page re-loading. You can even go further and make a polling to the server to render a certain section only via AJAX.

帥小哥 2024-12-26 18:02:10

我想一个简单的方法是有一个 last_updated 列,并查找该列大于您上次检查时的行,或者大于您上次找到的最大值的行。

然后,如果您使用 AJAX 和轮询或其他功能,您可以在会话中或仅在客户端上跟踪该时间。

I guess an easy'ish way would be to have a last_updated column and look for the rows where that column is greater than last time you checked, or greater than the greatest you found last time.

Then if you use AJAX and polling or something you could keep track of that time in a session or just on the client.

羞稚 2024-12-26 18:02:10

AJAX 将是必不可少的,除非您希望页面以某个设定的时间间隔重新加载。根据您想要在服务器上放置的负载量定期检查更新。将数据拉到页面即可。

AJAX will be imperative unless you want the page to reload at some set interval. Check for an update periodically depending on how much load you want to place on the server. Pull the data to the page and voila.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文