On Feb 25, 2011, at 01:16, Robert J. Maiolo wrote:
> On Thu, Feb 24, 2011 at 11:09 PM, tubiz wrote:
>> Please I would like to know how to auto increment a field in a table
>> in my database. I want to to be incremented once the action is clicked
>> upon.
> 
> why not just retrieve the value, increment then update the field?

Because that's not atomic. (Between the time you retrieve the value and the 
time you set the new value, another query may have changed the value already.)

Instead, you want to have the equivalent of the SQL...

UPDATE table SET field=field+1 WHERE somecondition;

...where it all occurs in a single query.

How to do this in CakePHP was recently asked in this group; here's one reply 
from that thread that shows one possible solution:

http://groups.google.com/group/cake-php/msg/022622017dd329f8




-- 
Our newest site for the community: CakePHP Video Tutorials 
http://tv.cakephp.org 
Check out the new CakePHP Questions site http://ask.cakephp.org and help others 
with their CakePHP related questions.


To unsubscribe from this group, send email to
[email protected] For more options, visit this group at 
http://groups.google.com/group/cake-php

Reply via email to