长整数在插入较短的列时进行转换,而不是截断.为什么?公式是什么?

2022-01-14 00:00:00 integer php mysql iec10967

我有一列 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

相关文章