RE: [PHP] Locking mysql tables with PHP
| From: | Jay Blanchard | Date: | Tue, 25 Nov 2003 13:47:58 +0000 |
| Subject: | RE: [PHP] Locking mysql tables with PHP | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-170877@lists.php.net to get a copy of this message | ||
[snip]
> [snip]
> is there a way I can get a number and increment it all in one query
> then?
> [/snip]
>
> UPDATE tblFoo SET value = (value+1) WHERE conditions
>
Hmm.. my bad - I get that bit, but can I do:
SELECT value WHERE conditions UPDATE tblfoo SET value= (value+1)
[/snip]
Essentially that is what the UPDATE statement is doing, you are
selecting values to be updated with the where condition. Your way is two
queries The SELECT (which locks, then releases) and the UPDATE (which
locks, the releases). In the split second between the select and update
the row is not locked, an undesirable conditions.