phpmysqlintegeriec10967

Long integer is transformed when inserted in shorter column, not truncated. Why? What is the formula?


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

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.


Solution

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

    The integer overflow will set the max allowed number in the DB as

    2147483647
    

    So you need bigint datatype for storing bigger integer