当数字超过2147483647时,将字符串转换为整数

$_GET[id];

$id=(int)$_GET['id'];

mysql store - int

I have a question about convert string into integer.

(Convert post id to make sure user don't send string)

and mysql store type - int


I notice if the id is bigger than 2147483647, the number become crazy.

what if website posts are more than 2147483647?

is any way to convert it into bigint? or I shouldn't convert string into int?

Do I have change mysql store type to - bigint?

Signed INT in MySql can only go up to 2^31, so yes -- you will have to convert the column to BIGINT.

Apart from that you must also deal with PHP's restrictions. An integer in PHP cannot be greater than PHP_INT_MAX (the exact value depends on the environment), so numbers larger than that have to be processed in string or floating point form if you stick to the primitives. Keeping the value as a string should be OK since it's an id, and you don't do math with ids.