Jump to content

Insert Unique Random String Into Database


The Little Guy

Recommended Posts

What would be the best way in insert a random string into the database, but the string cannot already exist in the database (the string will be case sensitive)?

 

I was just going to make a loop that will make a query more than one time if the string is already in the database, but is there a better way to do this?

What would be the best way in insert a random string into the database, but the string cannot already exist in the database?

 

I was just going to make a loop that will make a query more than one time if the string is already in the database, but is there a better way to do this?

 

Set the field as unique in the database, and use this to make a unique code.

$code = md5(uniqid(rand(), true));

 

You can take a substr() of that to get the right # of chars if you want.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.