RE: [PHP] Re: Auto Incrementing in PHP
| From: | Don Read | Date: | Sun, 19 Jan 2003 20:11:04 +0000 |
| Subject: | RE: [PHP] Re: Auto Incrementing in PHP | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-132191@lists.php.net to get a copy of this message | ||
On 19-Jan-2003 Don Mc Nair wrote:
> Thanks Guys
>
> I just needed a pointer. I decided to use the database and created two
> tables, one for invoice number and one for order number then defined a
> function to read the current number and the increment it.
>
That'll work, but it's not atomic. At high traffic loads you can get
duplicates.
You might want to consider a table with a auto_increment field. Do a dummy
insert, the get the value with :
mysql_query('SELECT last_insert_id() as id');
Regards,
--
Don Read dread@texas.net
-- "Beer is proof that God loves us and wants us to be happy."