Long integer is transformed when inserted in shorter column, not truncated. Why? What is the formula?(长整数在插入较短的列时进行转换,而不是截断.为什么?公式是什么?)
问题描述
我有一列 integer 类型的列,长度为 10:
I have a column of type integer with length 10:
`some_number` int(10) unsigned NOT NULL
我在此列中插入了一个太长的数字:
Into this column I insert a number that is too long:
$some_number = 715988985123857;
$query = "INSERT INTO this_table SET some_number = ?";
$stmt = $mysqli->prepare($query);
$stmt->bind_param('i', $some_number);
$stmt->execute();
当我查看表格中的内容时,现在的数字是:
When I look at what is in the table, the number is now:
2147483647
715988985123857如何以及为什么变成2147483647?
为什么它没有被截断?
这种转换背后的机制是什么,可以用一些公式计算得到的数字吗?
How and why did 715988985123857turn into 2147483647?
Why didn't it get truncated?
What is the mechanism behind this transformation, and can the resulting number be calculated with some formula?
我不是在寻找解决方案.我只是想了解具体的数字.
I'm not looking for a solution. I just want to understand the specific number.
推荐答案
http://dev.mysql.com/doc/refman/5.0/en/integer-types.html
整数溢出会将DB中的最大允许数设置为
The integer overflow will set the max allowed number in the DB as
2147483647
所以你需要 bigint 数据类型来存储更大的整数
So you need bigint datatype for storing bigger integer
这篇关于长整数在插入较短的列时进行转换,而不是截断.为什么?公式是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:长整数在插入较短的列时进行转换,而不是截断.为什么?公式是什么?
- 带有通配符的 Laravel 验证器 2021-01-01
- Mod使用GET变量将子域重写为PHP 2021-01-01
- Oracle 即时客户端 DYLD_LIBRARY_PATH 错误 2022-01-01
- SoapClient 设置自定义 HTTP Header 2021-01-01
- 没有作曲家的 PSR4 自动加载 2022-01-01
- 正确分离 PHP 中的逻辑/样式 2021-01-01
- Laravel 仓库 2022-01-01
- PHP Count 布尔数组中真值的数量 2021-01-01
- 从 PHP 中的输入表单获取日期 2022-01-01
- 如何定位 php.ini 文件 (xampp) 2022-01-01
