用户
 找回密码
 入住 CI 中国社区
搜索
查看: 2876|回复: 1
收起左侧

[版本 4.x] 开启事务后,如何加行锁

[复制链接]
发表于 2020-8-12 18:47:38 | 显示全部楼层 |阅读模式
开启事务后,如何加行锁。CI4有没有实现mysql的悲观锁,怎么使用?
 楼主| 发表于 2020-8-12 19:00:28 | 显示全部楼层
laravel的是这样子的:
   \DB::beginTransaction();
$talentBar = TalentBar::where('bar_id', $order->bar_id)->lockForUpdate()->first();
        $talentBar->account_balance = $order->amount * $talentBar->fc_ratio + $talentBar->account_balance;
        $talentBar->updated_at = $order->check_time;
        $talentBar->saveOrFail();
\DB::commit();   //提交事务
==========================================
在ci4中找不到和“lockForUpdate”相同的加行锁的用法。

本版积分规则