Send email from MySQL trigger when a table updated(当表更新时从 MySQL 触发器发送电子邮件)
问题描述
考虑一个表为table2,我喜欢在这个表上添加一个trigger update as
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 触发器发送电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:当表更新时从 MySQL 触发器发送电子邮件
基础教程推荐
- 是否可以执行按位分组功能? 2021-01-01
- SQL:使用来自具有相同列名的两个表中的数据... 2021-01-01
- 将 SQL Server DateTime 列迁移到 DateTimeOffset 2021-01-01
- 如何使用 mysql.connector 禁用查询缓存 2022-01-01
- 无法解决整理冲突 2021-01-01
- SQL 效率:WHERE IN 子查询 vs. JOIN 然后 GROUP 2021-01-01
- SQL Server 实例在登录协商期间返回无效或不受支持的协议版本 2021-01-01
- 在 SQL 中连接多个表 2021-01-01
- SSMS 中的权限问题:“对象 'extended_properties'、数据库 'mssqlsystem_resource'、... 错误 229)上的 SELECT 权限被拒绝" 2022-01-01
- 需要 MySQL 5.1 中的抽象触发器来更新审计日志 2021-01-01
