PHP で crc32 を作成していて、それを MySQL データベースのフィールドに格納する必要があります。32 ビット マシンと 64 ビット マシンでの結果にどのような懸念があるかを読んだ後、この数値をどのように格納するべきか疑問に思いました。これは、どちらのビットサイズのマシンでも同じ結果を得るために PHP で crc32 を処理する方法です。
<?php
$checksum = crc32("The quick brown fox jumped over the lazy dog.");
// On a 32-bit system it prints -2103228862 instead of
// 2191738434 which is correct and what prints on a 64-bit system.
// See the php.net manual page on crc32 for more information about
// 32-bit vs 64-bit.
echo "checksum without printf formatting: " . $checksum . "\n";
printf("%u\n", $checksum);
$string = sprintf("%u", $checksum);
echo $string . "\n";
?>
出力 (64 ビット マシンでは):
checksum without printf formatting: 2191738434
2191738434
2191738434
この数値はどのように MySQL に保存されますか? これまでに思いついたいくつかの選択肢を次に示します。
`hash1` CHAR(10) NOT NULL ,
`hash2` varchar(32) NOT NULL,
`hash3` int unsigned NOT NULL,
私は一緒に行くべきだと思われます:
`hash4` BIGINT UNSIGNED NOT NULL ,