IIRC, the OP wanted to generate a unique key precisely to keep from revealing the record ID to the end user... what about taking the auto_increment value (easy to generate, assured to be unique) adding its MD5 hash to another column in the table, then using that as the "published" ID? The only disadvantage I see is that the MD5 hash isn't very human-friendly, so using it for an account or member number, or something like that the user might have to write down or read to a customer service rep on the phone, might be difficult. -Jim On Fri, March 23, 2007 9:35 pm, Richard Lynch wrote: > Use auto_increment. > > It's not random, but you should never show it to the end user anyway, > so who cares? > > Another option is to use http://php.net/uniqid and you can create a > UNIQUE INDEX on the column and simply check mysql_errno() to see if > it's 1023 (or is it 2023?) when you insert to see if you had a > collision. > > On Wed, March 21, 2007 12:18 pm, ccspencer@xxxxxxxxxxxx wrote: >> Hello, >> >> I want to add a random unique ID to a Mysql table. Collisions >> are unlikely but possible so to handle those cases I'd like to >> regenerate the random ID until there is no collision and only >> then add my row. Any suggestions for a newbie as to the right >> way to go about doing this? >> >> Best, >> >> Craig >> >> ------------------------------------------------------ >> - Virtual Phonecards - Instant Pin by Email - >> - Large Selection - Great Rates - >> - http://speedypin.com/?aff=743&co_branded=1 - >> ------------------------------------------------------ >> >> >> ************************************** >> * * >> * Craig Spencer * >> * ccspencer@xxxxxxxxxxxx * >> * * >> ************************************** >> >> -- >> PHP General Mailing List (http://www.php.net/) >> To unsubscribe, visit: http://www.php.net/unsub.php >> >> > > > -- > Some people have a "gift" link here. > Know what I want? > I want you to buy a CD from some indie artist. > http://cdbaby.com/browse/from/lynch > Yeah, I get a buck. So? > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php