Generatinge Unique Id on the fly Mysql + PHP -


I am trying to come up with a solution specifically to generate a unique ID on the fly. The area of ​​use can be an order, product or plan ID, where no security is involved.

I do not like the idea of ​​generating random numbers and then DB should check its specificity and repeat the process, if it is not in this case where security is not a problem.

Besides, I do not like to use auto-emoticon id because it looks very easy.

My initial thought is that the combination of Auto Enerment ID + Timestamp has to convert the decimal value to hex, it seems like a random string and then finally prefixing and suffixing with 2 digit random strings.

  Generate function UID ($ num) {$ str = dechex (time () + intval ($ num)); $ Prefix = dashx (rand (1,15)); $ Suffix = decex (rand (1,15)); Return Strawper ($ suffix. $ Str. $ Prefix); }  

Where $ num is the auto_increment id returns such as E53D42A046

is the correct way to know what to do Is Collision Issues?

Thank you for all the responses ..!

I accept the usefulness of uniqid () but in this context, if the need for a unique Auto_Increment plays an important role, then how will it do this in uniqid. Passing it as a prefix is ​​a product ID that is very different in size. (153d432da861f, 99 99 99953d432f439bc0).

To further expand the area, ideally we want a unique code that randomly looks with absolute length and which can be reversed by the auto_ignment ID, Was made.

Such a function already exists - uniqid ()

It works on microseconds based on the timestamp - you can add a prefix based on the process ID to further refine it. There are some more robust versions, as well as -


Comments

Popular posts from this blog

java - org.apache.http.ProtocolException: Target host is not specified -

java - Gradle dependencies: compile project by relative path -

ruby on rails - Object doesn't support #inspect when used with .include -