简体   繁体   English

插入到mysql数据库中时int值更改-php

[英]Int value changes when insert into mysql database - php

I have a table in mysql with a field called "userId": 我在mysql中有一个表,字段名为“ userId”:

`userId` int(20) NOT NULL

Insert statement is: 插入语句为:

$result = mysql_query("INSERT INTO users (userId, firstName, lastName, dateCreated) VALUES (".$me['userId'].", '".$me['first_name']."', '".$me['last_name']."', CURDATE()) ")or die(mysql_error());

The value of userId when echoed in php is 100000517980247, but when inserted it changes to 2147483647. When I insert it into a varchar field it's fine. 在php中回显时,userId的值为100000517980247,但在插入时更改为2147483647。将其插入varchar字段中就可以了。 This has to be something really simple but I searched around a bit and I'm just not seeing it. 这一定很简单,但是我搜索了一下,却没有看到。

MySQL ints are a signed 32bit integer. MySQL整数是一个有符号的32位整数。 You're inserting a number that's far above the limit, so you're seeing the maximum possible integer, which is 2147483647. 您插入的数字远远超出限制,因此您看到的是最大可能的整数2147483647。

Change the data type to bigint for a 64bit data type, which will handle your number. 将数据类型更改为bigint以获得64位数据类型,它将处理您的号码。

You use the type INT. 您使用类型INT。 And you need to use type BIGINT. 并且您需要使用类型BIGINT。

http://dev.mysql.com/doc/refman/5.0/en/numeric-types.html http://dev.mysql.com/doc/refman/5.0/en/numeric-types.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM