Apparently MySQL's CRC32() function returns an unsigned BIGINT, while PHP returns hexadecimal value.
In PHP:
hash('crc32','hello world') == 7813f744
In MySQL:
SELECT CRC32('hello world') == 222957957
The PHP CRC32 value is stored in a CHAR(8) column.
I can't figure out how to turn the PHP generated hash into the same value that MySQL produces only using SQL. The obvious doesn't seem to work:
SELECT HEX(CRC32('hello world')) == D4A1185
SELECT CONV('7813f744',16,10) == 2014574404
Any ideas?
If you have 64-bit platform you can safely use crc32 function in PHP and CRC32
in MySQL. Quick test:
php > echo crc32('foobar') . "\n";
2666930069
MySQL:
>select crc32('foobar');
+-----------------+
| crc32('foobar') |
+-----------------+
| 2666930069 |
+-----------------+
1 row in set (0.00 sec)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With