问题描述
显然,MySQL的CRC32()函数返回一个无符号的BIGINT,而PHP返回十六进制值。在PHP中:
在MySQL中: p>
SELECT CRC32('hello world')== 222957957
CRC32值存储在CHAR(8)列中。
我无法弄清楚如何将PHP生成的哈希变成与MySQL生成的值相同的值仅限SQL 。显然似乎并不奏效:
SELECT HEX(CRC32('hello world'))== D4A1185
SELECT CONV('7813f744',16,10)== 2014574404
有什么想法?
如果你有64位平台,你可以安全地使用在PHP中的功能和 CRC32
in MySQL的。快速测试:
php> echo crc32('foobar')。 \\\
;
2666930069
MySQL:
> select crc32('foobar');
+ ----------------- +
| crc32('foobar')|
+ ----------------- +
| 2666930069 |
+ ----------------- +
1行(0.00秒)
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 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 with only 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)
这篇关于如何将PHP的crc32哈希转换为MySQL等价物?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!