java crc32 mysql,如何将PHP的crc32哈希转换为MySQL等价物?

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)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值