如何将PHP的crc32哈希转换为MySQL等价物? [英] How to convert PHP's crc32 hash into the MySQL equivalent?

查看:211
本文介绍了如何将PHP的crc32哈希转换为MySQL等价物?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

显然,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位平台,你可以安全地使用 crc32 在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等价物?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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