2019-06-25 13:51:47 1400次浏览 3条回答 0 悬赏 10 金钱

$db->createCommand($sql2)->execute(); 不能使用模型赋值,对吧?

最佳答案

  • return19931112 发布于 2019-06-26 09:43 举报

    事务跟模型没有必然的联系,只跟数据库操作有关,要在Model中使用,可以参考:

    public function testTransaction()
    {
        $transaction = static::getDb()->beginTransaction();
        try {
            /* 业务代码 */
            $transaction->commit();
        } catch (\Exception $exception) {
            /* 异常处理 */
            $transaction->rollBack();
        }
    }
    
您需要登录后才可以回答。登录 | 立即注册
PHP学院的中学生
副总裁

PHP学院的中学生

注册时间:2018-10-23
最后登录:2024-04-07
在线时长:168小时1分
  • 粉丝29
  • 金钱4730
  • 威望30
  • 积分6710

热门问题