cedivad cedivad - 1 year ago 127
MySQL Question

PHP hashing function that returns an integer (32bit int)

The goal is to store the hash on a mysql database, using INT (not BIGINT or MEDIUMINT).

md5('string', true)
returns binary data, 16 bytes of hash. I thought i could grep the first 4 bytes and convert it to an INT(32bit/4bytes) integer, but i don't know how to do it.

What do you suggest? Thanks.

Answer Source
ord($hash[0]) * 16777216 + ord($hash[1]) * 65536 + ord($hash[2]) * 256 + ord($hash[3]) ;


unpack("L", substr($hash,0,4));

But Frosty Z's solution is better.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download