spotlightsnap spotlightsnap - 1 month ago 6
MySQL Question

Inserting random characters to MYSQL Database

I want to add 100 entry to users table numbers field, random characters length is 10, all entry should be unique as well. How can i achieve this using MYSQL query code ?

Or do i need to use PHP ?

Help me with code snippets please. Thanks.

Answer

in mysql u can do like :

insert into table ( SUBSTRING(MD5(RAND()) FROM 1 FOR 10) , field2 , field3) , ( SUBSTRING(MD5(RAND()) FROM 1 FOR 10) , field2 , field3) , .........

..............

in php see this 2 links :

http://stackoverflow.com/questions/307486/short-unique-id-in-php/307773#307773

http://stackoverflow.com/questions/637278/what-is-the-best-way-to-generate-a-random-key-within-php