Heim  >  Artikel  >  Backend-Entwicklung  >  32位和64位PHP和MySQL里的整型范围

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

WBOY
WBOYOriginal
2016-06-23 13:16:27927Durchsuche

一个字节有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.

64位Ubuntu 14.04,PHP_INT_MAX的值为9223372036854775807,跟MySQL中有符号的bigint型的最大值一样.

32位Ubuntu 14.04,PHP_INT_MAX的值为2147483647,跟MySQL中有符号的int型的最大值一样.

echo date('Y-m-d H:i:s', PHP_INT_MAX); 返回 2038-01-19 11:14:07

echo strtotime('2038-01-19 11:14:07'); 返回 2147483647

echo strtotime('2038-01-19 11:14:08'); 32位下返回空

也就是说,32位系统上PHP的time()最大只能返回2038-01-19 11:14:07的时间戳.

字段类型: `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位整数.

本文永久更新链接地址: http://www.linuxidc.com/Linux/2016-02/128479.htm

Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn