简体   繁体   English

插入表后,在mysql触发器中发送http请求

[英]Send an http request in mysql trigger after insertion in a table

I am working in PHP.I have to created a mysql trigger which fires an http request after insertion on table.Below is the code. 我在PHP中工作。我必须创建一个mysql触发器,在插入table之后触发一个http请求.Below是代码。

DELIMITER @@
CREATE TRIGGER Test_Trigger
AFTER INSERT ON insertsms
FOR EACH ROW
BEGIN
  SET @tt_json = (SELECT json_object(id,addtime,title) 
                  FROM insertsms WHERE id = NEW.id LIMIT 1);
  SET @tt_resu = (SELECT http_put(CONCAT('--url localhost--')));
END;
@@
DELIMITER ;

But I am getting errors like 但我得到的错误就像

Message: SQLSTATE[42000]: Syntax error or access violation: 1305 FUNCTION emg.json_object does not exist 消息:SQLSTATE [42000]:语法错误或访问冲突:1305功能emg.json_object不存在

Message: SQLSTATE[42000]: Syntax error or access violation: 1305 FUNCTION emg.http_put does not exist 消息:SQLSTATE [42000]:语法错误或访问冲突:1305功能emg.http_put不存在

How to remove this error? 如何删除此错误? I was not able to download the supporting files containing these functions.I have tested in localhost.Is there any other way to achieve my requirement? 我无法下载包含这些功能的支持文件。我已在localhost中测试过。有没有其他方法可以满足我的要求? Please anyone help me.. 请有人帮帮我..

Although it's technically possible I'd strongly discourage you from going this route for several reasons: 虽然技术上可行,但我强烈反对你走这条路线有几个原因:

  1. Using UDFs is a security risk on its own. 使用UDF本身就存在安全风险。 UDFs are available to all database users - you cannot grant EXECUTE privileges for them. UDF可供所有数据库用户使用 - 您无法为它们授予EXECUTE权限。

  2. Doing any non-transactional operations in a trigger is simply wrong . 在触发器中执行任何非事务性操作是完全错误的 Data changes made by DML statement (in your case it's an update) can and will be rolled back in a real world scenario. DML语句所做的数据更改(在您的情况下是更新)可以并将在实际场景中回滚。 You won't be able to undo your http calls. 您将无法撤消您的http呼叫。

  3. You're prolonging the time for insert transaction possibly causing lock-wait-timeouts for other update/insert operations. 您延长了插入事务的时间,可能导致其他更新/插入操作的锁定等待超时。

Highly recommended reading: 强烈推荐阅读:


Now most likely what you need is a work queue eg beanstalked . 现在很可能你需要的是一个工作队列,例如beanstalked Using such specialized middleware is much better than organizing queues with database. 使用这种专用中间件比使用数据库组织队列要好得多。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM