bigint 没有正确插入
bigint not insert correctly
我有一个数据库和一个 bigint 列类型。每次我向该列插入值时,我总是得到错误的数字。例如,我插入值“198705122006041001”,它总是插入这个值“2147483647”。
我的项目使用 laravel,如果我使用 eloquent 显示 bigint,它不会正确显示,但如果我手动使用 PDO,它会正确显示。
你应该再检查一遍,因为它肯定是 int
,而不是 bigint
。 2147483647
是 maximum possible value for signed int
PHP 没有 bigint 数据类型,它溢出并使用 int.max 代替。您必须将 bigints 表示为字符串或浮点数。请注意,浮动并不精确,可能会导致意外。
在 MySQL 中进行数学转换,必要时不要忘记转换为 bigint。
参见https://laracasts.com/discuss/channels/eloquent/fbid-bigint-with-model-and-eloquent。一位 Laravel 用户遇到了同样的问题,最终不得不将结果转换为字符串。
另一位用户评论指出,XAMPP 仅提供 32 位 PHP 二进制,这限制了 PHP 整数的大小。
使用此代码检查您的 PHP 整数大小:
<?php
echo "Integer size can be determined using the constant PHP_INT_SIZE="
. (PHP_INT_SIZE * 8)
. " bits, maximum value using the constant PHP_INT_MAX="
. PHP_INT_MAX;
另见 http://php.net/manual/en/language.types.integer.php
安装 https://laravel.com/docs/5.3/homestead 并获取 64 位 PHP 二进制文件。
我有一个数据库和一个 bigint 列类型。每次我向该列插入值时,我总是得到错误的数字。例如,我插入值“198705122006041001”,它总是插入这个值“2147483647”。
我的项目使用 laravel,如果我使用 eloquent 显示 bigint,它不会正确显示,但如果我手动使用 PDO,它会正确显示。
你应该再检查一遍,因为它肯定是 int
,而不是 bigint
。 2147483647
是 maximum possible value for signed int
PHP 没有 bigint 数据类型,它溢出并使用 int.max 代替。您必须将 bigints 表示为字符串或浮点数。请注意,浮动并不精确,可能会导致意外。
在 MySQL 中进行数学转换,必要时不要忘记转换为 bigint。
参见https://laracasts.com/discuss/channels/eloquent/fbid-bigint-with-model-and-eloquent。一位 Laravel 用户遇到了同样的问题,最终不得不将结果转换为字符串。
另一位用户评论指出,XAMPP 仅提供 32 位 PHP 二进制,这限制了 PHP 整数的大小。
使用此代码检查您的 PHP 整数大小:
<?php
echo "Integer size can be determined using the constant PHP_INT_SIZE="
. (PHP_INT_SIZE * 8)
. " bits, maximum value using the constant PHP_INT_MAX="
. PHP_INT_MAX;
另见 http://php.net/manual/en/language.types.integer.php
安装 https://laravel.com/docs/5.3/homestead 并获取 64 位 PHP 二进制文件。