简体   繁体   中英

pdo transaction clarification with commit

New to using transactions and cannot find a definitive answer on this on the web. In this example, I realize query1 and query2 both must succeed for anything to be committed to the database and the catch will run if they don't...

Does code entered after commit() ( more code here in this example) ONLY run if the transaction occurred or will it run regardless?

try {
    $db->beginTransaction();

    query1

    query2

    $db->commit();

    **more code here**
}
catch(Exception $e)
{   
    $db->rollback();

    some error message
}

if an exception is thrown, remaining code in the try {} block will not be executed

http://php.net/manual/en/language.exceptions.php

When an exception is thrown, code following the statement will not be executed, and PHP will attempt to find the first matching catch block.

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