RE: transaction locking

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



 
Thanks Miles and John for you answers... Yes I am using MySQL.
I think I can work it to use the dB to generate these. I ran into 
The problem originally because this dB was taking up where a different
Tool was ending and I needed to start with a specific number scheme. Here
Is a though... If I have a field in MySQL that had numbers already populated
Along with an auto incremental column... Can I remove this auto column and
Change the properties of the already populated column to auto generate? Will
It accept the numbers already there or will I have to start from scratch?

In other words I know that in the dB if you setup a new table and set a
column\
To auto increment, it starts a the number 1. Can this be set to a higher
number
Say 5454 ??

TIA

Aleks
-----Original Message-----
From: Miles Thompson [mailto:milesthompson@xxxxxxxxxxxxxxx] 
Sent: Friday, December 05, 2003 8:24 AM
To: php-db@xxxxxxxxxxxxx
Subject: Re:  transaction locking

Aleks,

Many programmers learned the hard way that the scheme you are proposing did
not work when they went from a single user to a networked environment.

You've not said what database you are using. If MySQL you can let it's
autoincrement increase your key automatically, perhaps feed it back as
confirmation of completion. Using this you will not get duplicates as the
insert is unique per connection. Check the MySQL docs for the last insert
id.

Try this - it works and takes a load off your code.

Alternately, if you want to use your own scheme, establish a lookup table
with two fields: keyvalue and tablename. Write a function that with the
table name as a parameter, locks the table, retrieves the keyvalue, adds one
to it, updates and exits. You will have to test for locks, you may end up
with gaps in your key numbers.

If possible, let the database do the work for you.

Regards - Miles Thompson

At 06:11 AM 12/5/2003 -0700, Aleks Kalynovych wrote:
>Good morning all,
>
>I have a couple forms that generate a unique ID based on taking the 
>highest number in the ID column adding 1 to its value. The problem is 
>that I donâ??t save that number until the form is submitted. If 2 or 
>more persons fill out the form at the same time they all get the same 
>ID number.  I hope that there are some suggestions on how to accomplish 
>this with a better method
>
>TIA for your help
>
>Aleks
>
>--
>PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: 
>http://www.php.net/unsub.php

--
PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit:
http://www.php.net/unsub.php

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux