简体   繁体   中英

MySQL PDO Transactions Exceptions

Say I have a bunch of queries that I am running in a consecutive order using PHP/MySQL PDO. So ideally I start by BeginTransaction and finish by a commit.

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. http://www.php.net/manual/en/pdo.rollback.php

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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