在PHP中为Mysql数据库生成唯一字符串 [英] Generating Unique String in PHP for Mysql Database

查看:99
本文介绍了在PHP中为Mysql数据库生成唯一字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何生成唯一的密钥并将其插入到我的mysql数据库中?
这是我目前使用的:

How can I generate a unique Key and insert it into my mysql database?
This is what I currently use:

echo uniqid(time(), true);

您能否告诉我它是否是唯一密钥?

Can you tell me wether it is a unique key or not?

推荐答案

您可以使用以下代码获取32个字符的唯一ID

you can use following to get unique id with 32 chars

md5(uniqid(time(), true))

或者您可以将sha1用作40个字符

or you can use sha1 like with 40 chars

sha1(uniqid(time(), true))

这篇关于在PHP中为Mysql数据库生成唯一字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆