zoukankan      html  css  js  c++  java
  • YII事务

    这里说一下关于使用数据库事务几项功能的改进。

    首先,你现在可以像下面这样以回调形式的事务工作:

    $connection->transaction(function(){
        $order = new Order($customer);
        $order->save();
        $order->addItems($items);
    });
    

    这相当于下列冗长的代码:

    $transaction = $connection->beginTransaction();
    try {
        $order = new Order($customer);
        $order->save();
        $order->addItems($items);
        $transaction->commit();
    } catch (Exception $e) {
        $transaction->rollBack();
        throw $e;
    }
    

    其它,事务可以触发一系列事件。 例如, a beginTransaction event is triggered by a DB connection when you start a new transaction; and a commitTransaction event is triggered when the transaction is successfully committed. You can respond to these events to perform some preprocessing and post-processing tasks when using transactions.

    最后,开始一个新的事务时,您可以设置事务隔离级别(例如READ COMMITTED)。例如,

    $transaction = $connection->beginTransaction(Transaction::READ_COMMITTED);
    
    事务隔离级别 脏读 不可重复读 幻读
    读未提交(read-uncommitted)
    不可重复读(read-committed)
    可重复读(repeatable-read)
    串行化(serializable)
  • 相关阅读:
    腾讯云通信 资料
    获取openid 的步骤
    微信公众号推送通知接口
    患者接收医生的消息通知完整流程(微信公众号的界面)
    阿里im即时通讯 h5 demo
    微信微信JS-SDK 6.0.2 填坑笔记
    2018秋季寒假作业1-介绍自己
    勿忘初心
    Ubuntu中安装eclipse
    vim的常用指令
  • 原文地址:https://www.cnblogs.com/jimz/p/10675105.html
Copyright © 2011-2022 走看看