If I follow you correctly, is the scenario below possible.??
Let's say there are 2 users accessing the app at the same time (user A and
B). Here's the sequnce of operation...
1. user A insert into table (get id = 1 from auto increment value)
2. user B insert into table (get id = 2 from auto increment value)
3. user A get value from $id = LAST_INSERT_ID() (id = 2)
4. user B get value from $id = LAST_INSERT_ID() (id =2)
5. user A update table where id = 2
6. user B update table where id = 2
in the scenario above, the row with id = 1 doesn't get his file number (fin)
while the row with id = 2 gets the value for his file number twice...
How can we make sure that those 3 processes are atomic operation (insert
table -> get id from LAST_INSERT_ID() -> update table) ??
> For example, I would use (not tested):
> // code to create a record (i.e., INSERT INTO your_table (whatever)
> VALUES ('$whatever') )
> $id = LAST_INSERT_ID();
> The above statement finds the last record added to the database (the
> index of the record) and then I would create my application-number
> and store it in that record -- like so:
> // code to create the application-number (i.e., $application-number =
> 'AAA' . $id; )
> $query = "UPDATE your_table SET application_number =
> '$application_number' WHERE id = '$id' ";
> $result = mysql_query($query) or die('Error, query failed');
> That way you should not have any duplications and you have
> application-numbers (as you want )that are tied to the auto-numbering
> of the table's index.
> http://sperling.com http://ancientstones.com http://earthstones.com
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
View this message in context:
Sent from the PHP - General mailing list archive at Nabble.com.
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php