使用 PHP 创建随机 mysql ID 的最佳方法是什么 [英] what is the best way to create random mysql ID using PHP
本文介绍了使用 PHP 创建随机 mysql ID 的最佳方法是什么的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在构建一个应用程序,它需要每个用户的随机唯一 ID,而不是序列
i'm building an application that needs a random unique id for each user not a sequence
mysql 数据库
ID Username
对于我唯一的随机 ID,最好的方法是什么?
for my unique random ID, what is the best way to do that?
推荐答案
PHP 提供了一个 uniqid
函数,我想这可能会奏效.
PHP provides a uniqid
function, which might do the trick, I suppose.
请注意,它返回的是字符串,而不是整数.
Note it's returning a string, though, and not an integer.
另一个想法是生成/使用一些 GUID -- 在uniqid
手册页的用户注释.
Another idea would be to generate / use some GUID -- there are some proposals about that in the user notes of the manual page of uniqid
.
这篇关于使用 PHP 创建随机 mysql ID 的最佳方法是什么的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文