开发者

how can i lock the row of a table?

开发者 https://www.devze.com 2023-02-28 01:12 出处:网络
Let\'s assume I \'ve a table and want to select the first 10 rows from that table but I want to be sure tha开发者_高级运维t no other scripts will select the

Let's assume I 've a table and want to select the first 10 rows from that table but I want to be sure tha开发者_高级运维t no other scripts will select the same rows I've previously got by the first script.

How can I do that?

my table contains one primary key. Let's say id is the column name. So my first script is running and select the ids: 1, 2, 3 .... 10

Then that script will play with the returned ids. In the same time, I'm running a second script and do the same select. But I don't want him to get the first 10 ids.

How can i lock the row table in cakephp ? please help me thanks in advance....


$number = 0
$SQL = "SELECT * FROM table WHERE .... LIMIT $number, 10"
$number += 10


its more for read locking but im sure you can get some ideas here https://github.com/infinitas/infinitas/tree/beta/core/locks


I'm not sure it's possible without using native SQL (SELECT FOR UPDATE). There is an interesting thread here

https://groups.google.com/forum/?fromgroups=#!topic/cake-php/WCvWGsTTRjw

0

精彩评论

暂无评论...
验证码 换一张
取 消