samedi 26 août 2017

How to make more than 6 characters random alphanumeric by this code in trigger of MySQL?

I have a form for request registering by php and html. I found a code to make 6 character random string for tracking code and should not be duplicate.this code is in triggers for users table in mySql before inserting new row.

How can I make more than 6 characters random alphanumeric by this code in trigger of MySQL?

And in your opinion is this code useful or is better than a code for random string in php??

Whats your suggestion?

BEGIN
  declare ready int default 0;
  declare rnd_str text;

  while not ready DO set rnd_str := LOWER(lpad(conv(floor(rand()*pow(36,6)),10, 36), 6, 0));
     if not exists (select * from stu where st_trc = rnd_str)
     then
       set new.trck= rnd_str;
       set ready := 1;
     end if;
   end while;
END




Aucun commentaire:

Enregistrer un commentaire