简体   繁体   English

MySQL PDO交易异常

[英]MySQL PDO Transactions Exceptions

Say I have a bunch of queries that I am running in a consecutive order using PHP/MySQL PDO. 假设我有很多查询,这些查询是使用PHP / MySQL PDO连续执行的。 So ideally I start by BeginTransaction and finish by a commit. 因此,理想情况下,我从BeginTransaction开始,然后由一次提交结束。

Now, assume that one of the queries threw an exception in the middle of the run before the commit. 现在,假设其中一个查询在提交之前的运行过程中引发了异常。 Do I have to roll back when I catch the exception to handle it? 捕获异常后是否需要回滚? Or just ignore assuming it will roll back automatically because the commit call is not made? 或者只是忽略假设它会由于未进行提交调用而自动回滚的假设?

Thanks. 谢谢。

You could try calling the rollback function in the catch block if you want to be sure. 如果您想确定的话,可以尝试在catch块中调用rollback函数。 http://www.php.net/manual/en/pdo.rollback.php http://www.php.net/manual/zh/pdo.rollback.php

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

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