简体   繁体   English

MySQL事务-如何分组?

[英]MySQL Transaction - How to group?

I just learned about transaction few days ago and I find it very useful in some situation like when I update few tables and the script may fail in the middle of the operation, quite nice. 我几天前才刚学到事务,在某些情况下(例如,当我更新一些表时,脚本可能会在操作过程中失败)非常有用。

However, how can I group them ? 但是,如何将它们分组? It can happen that a query is ran between two queries in the transaction but I don't want it to rollback. 一个查询可能在事务中的两个查询之间运行,但是我不希望它回滚。 Is there a way that I can group query without a new connection ? 有没有一种方法可以在没有新连接的情况下对查询进行分组?

I have searched but I got poor to nothing result. 我进行了搜索,但结果却很差。

I am using InnoDB, PHP/PDO + MySQL. 我正在使用InnoDB,PHP / PDO + MySQL。

Thanks. 谢谢。

you can try with the begin-end , where you can execute multiple queries inside those tags. 您可以尝试begin-end ,您可以在这些标记内执行多个查询。 You are working with TRANSACTIONS, so you only have two options COMMIT and ROLLBACK, if your query is not successful it will ROLLBACK (no more option), Please take a look to this post 您正在使用TRANSACTIONS,因此只有两个选项COMMIT和ROLLBACK,如果查询不成功,它将返回ROLLBACK(没有更多选项),请看一下这篇文章

START TRANSACTION inside BEGIN ... END context or outside and LOOP syntax 在BEGIN ... END上下文内或外部以及LOOP语法中进行START TRANSACTION

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

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