【发布时间】:2017-06-26 06:58:14
【问题描述】:
请任何人帮助我! 在我的项目中,我有锁定记录的交易:
namespace App\Console\Commands;
use Illuminate\Console\Command;
class Testing extends Command {
protected function handling()
{
DB::beginTransaction();
try {
$posts = Posts::lockForUpdate()->find(1);
//run step 1
//run step 2
//run step 3
} catch (\Exception $e) {
DB::rollback();
}
}
}
在我的例子中,当它运行时,我从命令中调用它:
php artisan test:run
...
running step 1
...
...
running step 2
..
..
Ctrl C
-> quit command.
事务不提交并永远锁定记录。
我可以在命令强制退出时提交事务吗?
【问题讨论】:
标签: php mysql laravel locking pessimistic