[EMAIL PROTECTED] wrote:
Stut writes:
[EMAIL PROTECTED] wrote:
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?

1) Not even slightly PHP related.

Perhaps not.  It is Mysql related.  And seeing other Mysql discussion
on this list inspired me to ask.

I refer you to the comment made earlier today by one of my honourable colleagues regarding murder.

2) Why random? Incrementing not good enough for you?

I want to use it in a way that will expose it to the user.  And I
don't want to give out information as to the order of records in
my database.

This is not security. Your site should prevent them from accessing data they should not be accessing. If you're worried that they can do this simply by changing a number in a query string then you really need to rethink the way the site works.

If you decide to ignore my advice, then the only way to do this is to set the ID field as unique, pick a random number and try to insert the row. Repeat until the insert succeeds. Yes it sucks, but so does what you are trying to do.

-Stut

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

Reply via email to