PHP/MySQL - Best way to create unique random string?

后端 未结 10 2146
囚心锁ツ
囚心锁ツ 2020-12-15 04:20

How do I create a random unique string in MySQL?

when I need to create a random string in PHP I use this function:

public function generateString($le         


        
10条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-15 04:55

    Take a look at the uniqid function and the pecl uuid extension. Either one can be used as the basis for generating guids, although if you plan to have a cluster, you will want to insure that you have something extra that insures that two servers don't generate the same id. Having a per server configuration that adds as prefix or suffix to the id is sufficient to address that issue.

提交回复
热议问题