I am creating a unique id and would like to know what field structure I should be using. I am creating the id in php using md5 and uniqueid.

md5(uniqid($filename))

I have set the field in the database to varchar. I wanted to know if this was correct and also if correct how many chacaters should it be set to.

Many thanks

有帮助吗?

解决方案

MD5 returns 128 bit values which can be represented as a sequence of 32 hexadecimal characters, which is also the type of value PHP’s md5 function returns. So CHAR(32) would fit perfectly.

You could also turn the value into binary, i. e., 8 bit per byte instead of 4 bit per byte. This can be done with PHP’s md5 function by setting the second parameter raw_output to true. Or in MySQL using the UNHEX function. In that case BINARY(16) would suffice.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top