You are here: Re: Mutex access on a database? « PHP Programming Language « IT news, forums, messages
Re: Mutex access on a database?

Posted by Colin McKinnon on 09/13/05 12:02

Bill Godfrey wrote:

> gordon@hammy.burditt.org (Gordon Burditt) wrote:
>> If you perform a query like:
>> update foo set bar=bar+1 where id = '$userIdx';
>
> Ah ha. I must confess, I only know SQL from cribbing the commands
> phpMyAdmin creates. I didn't realise you could do that.
>
>> it should be atomic in the database without the need for explicit
>> locks, as it's all done in one SQL statement.
>
> If the database server (MySQL) will enforce atomic access, thats perfect.
>

Presumably because you want to read either the prev or new value? In that
case you'll need to lock the tables first:

LOCK TABLES foo READ;
SELECT bar FROM foo WHERE id = '$userIdx';
UPDATE foo SET bar=bar+1 WHERE id = '$userIdx';
SELECT bar FROM foo WHERE id = '$userIdx';
UNLOCK TABLES;

(quick hack, not tested YMMV)

C.

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация