I’m using PHP and MySQL and
I have a table with 3 fields ((ID, Username, PID)).
I want the PID field to contain strings of 8 unique characters.
My solution is to generate the random string in PHP and check if it exists. If it exists then it will generate another string.
Is there any better solution that will save processing time, like a MySQL trigger or something like that?
This will give you a random 8 character string:
Found here: http://www.richardlord.net/blog/php-password-security
Or if the username field is unique you could also use:
Though it’s extremely unlikely, particularly for the md5, neither case guarantees a unique string, so I would probably do something like this:
… which would probably only yield 1 ‘check’ query, maybe 2 in unique cases, and would ensure a unique string.