2

I have a web application which needs to send multiple Ajax request to a PHP page (backend.php)

There is an Oracle table, let's say T1 with 2 int fields min and max (for this example is enough, actually it's a bit more complex).

Backend.php needs to read mix and max, update these values (let's say min += 2, max += 3), then return min and max via some JSON.

In this case I can't use Oracle Sequences (because in the real application there are N rows).

I want to put a lock on the row, to avoid different Ajax calls reading the same values from the row.

I tried to run (via PHP's OCI) something like SELECT a, b FROM t1 FOR UPDATE SKIP LOCKED but it seems not to work, 2 Ajax calls sometimes return the same A and B values.

How can I make locks working? Is there a better way? Thank you.

4

1 回答 1

0

我不确定您是否需要显式锁。一个简单的

update T1 set min=min+2, max=max+3 where ...

将自动锁定受影响的行。

您可能需要花药选择来返回更新的值(或在 PL/SQL 中使用 RETURNING)

于 2013-04-20T11:31:32.347 回答