Bladephp: Now with 7+ codeigniter, php, and laravel project 7+ php project From $18/Year From Rs. 1000/Year

Pessimistic Locking in Laravel 5

by
Category:laravel
mysql laravel
Pessimistic Locking in Laravel 5

In some cases you do not want anyone to perform any action with a record, you are working with. I such case you may take possessiong of a given record using DB lock.

Laravel offers 2 methods to deal with pessimistic locking.

sharedLock

Shared lock is, when more than one transaction is granted read access to a given record. One transaction gets shared lock on a record.

DB::table('tbl_order')->where('amount', '>', 100)->sharedLock()->get();

 lockForUpdate

You can use it, when reading to prevent the rows from being modified or from being selected with another shared lock. Or you can lock some row(s) until your transaction finishes updating.

DB::table('tbl_order')->where('amount', '>', 100)->lockForUpdate()->get();

0 Comments


Html code work in comment box


Related Post