简体   繁体   English

pdo事务提交确认

[英]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... 在此示例中,我意识到query1和query2都必须成功才能将任何内容提交到数据库,并且如果不这样做,则捕获将运行...

Does code entered after commit() ( more code here in this example) ONLY run if the transaction occurred or will it run regardless? 在commit()之后输入的代码(在本示例中为更多代码 )仅在发生事务时才运行,还是会运行?

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 如果抛出异常,将不执行try {}块中的其余代码

http://php.net/manual/en/language.exceptions.php 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. 引发异常时,将不执行该语句之后的代码,PHP将尝试查找第一个匹配的catch块。

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

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