我在PHP中創建了一個crc32,並且需要將它存儲在MySQL數據庫的一個字段中。在閱讀了關於如何關注32位和64位機器的結果後,我想知道如何存儲這個數字。這是我如何處理PHP中的CRC32得到任何bitsize機上相同的結果:如何在MySQL中存儲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 ,
只需使用一個64位無符號場(UNSIGNED BIGINT)。 –