表更新时从MySQL触发器发送电子邮件 [英] Send email from MySQL trigger when a table updated

查看:517
本文介绍了表更新时从MySQL触发器发送电子邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

将一个表视为table2,我想在此表update上添加一个trigger作为

Consider a table as table2, i like to add a trigger on this table update as

select Num into num from table1 where ID=new.id;
BEGIN
DECLARE done int default false;
DECLARE cur1 CURSOR FOR select EmailId from users where Num=num;
DECLARE continue handler for not found set done = true;
OPEN cur1;
my_loop: loop
    fetch cur1 into email_id;
    if done then
        leave my_loop;
    end if;
    //send mail to all email id.
end loop my_loop;
close cur1;
END;

有什么简单的方法可以在有评论的地方写东西吗?要将电子邮件发送到从表users中检索到的所有电子邮件ID.

Is there any simple method to write in the place commented? To send a email to all the email id retrieved from table users.

我在XAMPP(phpmyadmin)中使用MySQL.

I am using MySQL in XAMPP(phpmyadmin).

推荐答案

我反对该解决方案.将发送电子邮件的负担放在数据库服务器中可能会非常糟糕.

I'm against that solution. Putting the load of sending e-mails in your Database Server could end very bad.

我认为,您应该做的是创建一个表,将要发送的电子邮件排入队列,并有一个过程检查是否有要发送的电子邮件,如果发送成功,则将其发送.

In my opinion, what you should do is create a table that queues the emails you would want to send and have a process that checks if there are emails to be sent and send them if positive.

这篇关于表更新时从MySQL触发器发送电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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