32位和64位PHP和MySQL里的整型范围

一个字节有8位,所以32位int型占用32位/8位=4个字节,64位int型占用64位/8位=8个字节.

32位,64位无符号整型最大值:
2^64-1 = 18446744073709551615
 2^32-1 = 4294967295

 32位,64位有符号整型最大值:
 (2^32)/2-1 = 2147483647
 (2^64)/2-1 = 9223372036854775807

减1是因为整型包括0.

字段类型: `posted` int(10) unsigned NOT NULL DEFAULT '0'
 32位MySQL上(64位MySQL也是如此),插入一个比32位无符号int型最大值 2^32-1 = 4294967295 更大的数会发生错误:
UPDATE `punbb`.`pb_topics` SET `posted` = '4294967296' WHERE `pb_topics`.`id` = 1;
 Warning: #1264 Out of range value for column 'posted' at row 1
不过,MySQL可以用8个字节的bigint类型来存储64位整数.

猜你喜欢

转载自www.linuxidc.com/Linux/2016-02/128479.htm