Re: generating unique id's

From: Date: Mon, 03 Jul 2000 00:42:43 +0000
Subject: Re: generating unique id's
References: 1  Groups: php.db 
Request: Send a blank email to php-db+get-811@lists.php.net to get a copy of this message
Hello Cody, On 28-Jun-00 20:10:31, you wrote: >I need to generate a unique id. The problem I am running into is this: >I have a for loop that generates a bunch of id's using the time() >function, the problem is that since the for loop only takes less than a >microsecond, and the precision of the time() function is a microsecond, >all the id's are the same. I looked into using uniqid(), which according >to the PHP manual generates an INT. However, I tested it out, and in a >microsecond it DOES generate a series of different, random STRINGS, mix of >ints and characters, NOT an INT, which like I said is what the PHP manual >uses. MySQL requires that the primary key be an INT, so I can use uniqid() >function to generate this id, because its a string. >What can I do? >In summary, generate a whole list of unique INTEGER id's in under a >microsecond... The right solution for your problem is to use sequences. On databases that don't support sequences, like MySQL, you may emulate them with tables with auto_increment fields. You may want to try Metabase which is a PHP database abstraction package that implements sequences in a database independent way. It uses separate tables with an auto-incremented field in MySQL. As a bonus, if you use this package to develop your applications you may easily port them to work with other databases with almost no effort, just in case you decide that you would like to use more capable databases than MySQL. http://phpclasses.UpperDesign.com/browse.html/package/20 Regards, Manuel Lemos Web Programming Components using PHP Classes. Look at: http://phpclasses.UpperDesign.com/?user=mlemos@acm.org -- E-mail: mlemos@acm.org URL: http://www.mlemos.e-na.net/ PGP key: http://www.mlemos.e-na.net/ManuelLemos.pgp --

« previous php.db (#811) next »