PHP和MySql中32位和64位的整形范围是多少_php实例

WBOY
Release: 2016-06-07 17:09:17
Original
1416 people have browsed it

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

数据类型

LP64

ILP64

LLP64

ILP32

LP32

char

8

8

8

8

8

short

16

16

16

16

16

_int32

N/A

32

N/A

N/A

N/A

int

32

64

32

32

16

long

64

64

32

32

32

long long

N/A

N/A

64

N/A

N/A

pointer

64

64

64

32

32

以上内容是小编给大家介绍的32位和64位的整形范围,希望对大家有所帮助。

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!