将不正确的Integer(2147483647)插入MySQL? [英] Incorrect Integer (2147483647) is inserted into MySQL?

查看:133
本文介绍了将不正确的Integer(2147483647)插入MySQL?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好的,所以我一直在研究Steam Web API,我将其中一个值存储在名为$steam64的变量中.当我使用此代码片段将其插入到mysql数据库中时,它会插入一个与该变量中存储的整数不同的completley整数.

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);返回真实的int,回显它也是如此.不太确定这里发生了什么,我们将不胜感激.

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

推荐答案

可能是因为您将查询用双引号引起来,但是变量用单引号引起来,因此将其视为文字,并且如果该列为诠释您会得到一个0.

It's probably because you are wrapping the query in double quotes, but the variable is in single quotes, so it's being treated as a literal, and if the column is int you will get a 0 instead.

尝试一下:

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

另外,在被炒鱿鱼之前,请务必先阅读 SQL注入,以防万一没有清除直接发布到sql语句中的变量.

Also, before I get flamed, be sure to read up on SQL injection in case you are not sanitizing variables being posted directly into sql statements.

-更新-

根据您对价值被倾销"的评论;对于32位系统,您要插入的数字太大. 32位的最大值为 4,294,967,295 ,而64位的最大值为 18,446,744,073,709,551,615 .我建议将您的列转换为varchar(100)哈希而不是int,或切换到64位系统.关于最大整数的很棒文章 "和"此处.

Based on your comment of "value being dumped"; the number you are trying to insert is too large for 32-bit systems. The max for 32-bit is 4,294,967,295, and the max for 64-bit is 18,446,744,073,709,551,615. I'd recommend converting your column into a varchar(100) hash rather than an int, or switch to a 64 bit system. Great article about max ints here, and here.

这篇关于将不正确的Integer(2147483647)插入MySQL?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆