Incorrect Integer (2147483647) is inserted into My

2019-01-01 13:34发布

Alright, so I've been toying around with the Steam Web API, I have one of the values stored in a variable called $steam64. When I use this code snipper to INSERT it into a mysql database it insert a completley different integer than what is stored in the variable.

$sql_query = "INSERT INTO users_info (steam64) VALUES ('$steam64')";

var_dump($steam64); returns the real int, so does echoing it. Not too sure what is going on here, any help is appreciated.

10条回答
与君花间醉酒
2楼-- · 2019-01-01 14:14

2147483647 is the largest int value for mysql. Just change the type from int to bigint.

查看更多
高级女魔头
3楼-- · 2019-01-01 14:16

The integer type INT is 4Bytes storage, you get from -2^(4*8-1)=-2147483648 to 2^(4*8-1)-1=2147483647, when you have "signed" flags, if you change the flags to unsigned you will have a range from 0 to 2^(4*8)-1 . MySQL support BIGINT being 8Bytes storage. If you try save a value greater, you will save the max value of the range

查看更多
余生无你
4楼-- · 2019-01-01 14:17

The largest value for data type INT is 2147483647. If the number you're inserting is bigger than 2147483647, then it will cause the problem. For solution, change the data type from INT to BIGINT as BIGINT has a maximum value of 9223372036854775807, it might solve your problem. Have a look at this site: https://dev.mysql.com/doc/refman/5.7/en/integer-types.html

查看更多
明月照影归
5楼-- · 2019-01-01 14:18
CREATE TABLE `dvouchers` (
  `2147483647` int(3) NOT NULL auto_increment,
  `code` varchar(12) NOT NULL default '1',
  `type` char(1) NOT NULL default '$',
  `count` int(3) unsigned NOT NULL default '0',
  `amount` int(3) unsigned default '0',
  `notes` text,
  `expiryDate` date default NULL,
  `fkUserAdminId` int(11) NOT NULL default '0',
  PRIMARY KEY  (`2147483647`),
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
查看更多
登录 后发表回答