我是靠谱客的博主 纯真皮皮虾,最近开发中收集的这篇文章主要介绍mysql 调用http请求_插入表后,在mysql触发器中发送http请求,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

bd96500e110b49cbb3cd949968f18be7.png

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.

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

Message: SQLSTATE[42000]: Syntax error or access violation: 1305 FUNCTION emg.http_put does not exist

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? Please anyone help me..

解决方案

Although it's technically possible I'd strongly discourage you from going this route for several reasons:

Using UDFs is a security risk on its own. UDFs are available to all database users - you cannot grant EXECUTE privileges for them.

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. You won't be able to undo your http calls.

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 e.g. beanstalked. Using such specialized middleware is much better than organizing queues with database.

最后

以上就是纯真皮皮虾为你收集整理的mysql 调用http请求_插入表后,在mysql触发器中发送http请求的全部内容,希望文章能够帮你解决mysql 调用http请求_插入表后,在mysql触发器中发送http请求所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(45)

评论列表共有 0 条评论

立即
投稿
返回
顶部