如何在MySQL查询为真后触发触发的事件? [英] How do I hook into an event triggered once a MySQL query is true?

查看:179
本文介绍了如何在MySQL查询为真后触发触发的事件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

一个人如何创建一个PHP脚本来一致地检查MySQL行,如果匹配了一个设置的查询,它将启动一个事件,例如发送电子邮件?

How does one create a PHP script that checks the MySQL row consistently and if a set query is matched, it starts an event, such as sending an email?

例如,在查询匹配项Fire上,开始发送电子邮件:

For example, on query match Fire start email:

To: me@me.com
From: php@trigger.com
Subject: Set query met, auto email complete.

它将围绕MySQL5.我被困住了.我最好在Perl或类似版本中做到吗? 也许它还可以向各种用户发送电子邮件? (这不是难事.:P)

It would be around MySQL5. I'm stuck on this. Am I best to do it in Perl or similar? Perhaps it could also email various users? (This isn't the hard bit. :P)

推荐答案

使用cron或类似的调度程序涉及轮询,该方法有效,但

Using cron or similar scheduler involves polling, which works but is brute force and ignorance. I can't recommend it: there's a time delay between when the row changes and when cron executes the checking program; repeated checking is a waste of resources.

解决方案是数据库触发器,请参见使用触发器可以通过触发器调用通过UDF进行外部应用程序?.每当表行着火或发生任何事情时,您都会收到一个事件,并且您的电子邮件发送程序会立即被调用.

The elegant solution is database trigger, see Using Triggers and Can triggers call an external application through a UDF?. You will get an event whenever your table row is on fire or something, and your email sending program is called immediately.

如果要使用Perl,请 Email::Simple /

If you want to use Perl, Email::Simple/Email::Sender is nifty.

这篇关于如何在MySQL查询为真后触发触发的事件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆