doulongsha5478 2012-02-04 22:49
浏览 31
已采纳

PHP脚本是否需要等待MySql触发器完成?

Database is MySQL. I am looking to implement a trigger that updates an aggregate rating table whenever a new rating is placed. Then there are some other similar use cases where I'm looking to implement triggers.

These triggers may be updating federated tables. So my question is: whether a php script that inserts a new rating will need to wait for the trigger to complete before the php script completes?

PS: I understand triggers is not a good idea to put logic, and may be I would be better off with some messaging such as RabbitMQ.

  • 写回答

1条回答 默认 最新

  • dpi74187 2012-02-04 23:08
    关注

    Triggers are synchronous; the INSERT/UPDATE/DELETE that spawned them blocks until the trigger completes executing, including any actions the trigger executes (and even any subsequent triggers spawned by those actions).

    Triggers are atomic. That is, if any change executed by the trigger fails, then the trigger fails, and it also cancels the change that spawned the trigger.

    Triggers also make changes in the scope of the same transaction that spawned the trigger. So changes made by the trigger can be committed/rolled back along with the changes that spawned the trigger. If triggers kept running while your PHP app finishes its transaction and exits, then there would be no way to ensure they happen in that transaction.

    This applies both to BEFORE triggers and AFTER triggers. Your app blocks until all triggers are finished.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 keil的map文件中Image component sizes各项意思
  • ¥30 BC260Y用MQTT向阿里云发布主题消息一直错误
  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM
  • ¥15 划分vlan后不通了
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)