[英]Integers being converted from 64bit to 32bit with PDO
I am storing 64bit Facebook ids in our mysql database. 我在我们的mysql数据库中存储了64位Facebook ID。 When I view the database table the values are 32bit.
当我查看数据库表时,值是32位。 I am using Laravel, with the PDO connection.
我正在使用带有PDO连接的Laravel。 The values, if dumped out, are correct in the bindings.
如果转储了这些值,则它们在绑定中是正确的。 Once executed they are different in the DB.
一旦执行,它们在数据库中将有所不同。 I have tried changing database from MariaDB to MySQL to see if it was the database causing it.
我尝试将数据库从MariaDB更改为MySQL,以查看是否是引起它的数据库。 Everything points to it being PDO.
一切都表明它是PDO。
This does not happen on my local development machine which is using the exact same version of PHP 7.0.15
. 在使用完全相同版本的
PHP 7.0.15
本地开发计算机上,不会发生这种情况。 I get no errors on either development or local. 我在开发或本地方面都没有错误。
MySQL and PHP are 64bit versions. MySQL和PHP是64位版本。 I have not been able to find anything that helps me resolve the issue.
我找不到能帮助我解决问题的任何东西。
I found this bug report from 2013 that clearly illustrates my issue but seems to have been resolved. 我发现2013年的此错误报告清楚地说明了我的问题,但似乎已解决。
In Laravel's Connection class the bindValues
method is checking the data type like so. 在Laravel的Connection类中,
bindValues
方法像这样检查数据类型。
public function bindValues($statement, $bindings)
{
foreach ($bindings as $key => $value) {
dump($value); // Value is correct at this point.
$statement->bindValue(
is_string($key) ? $key : $key + 1, $value,
is_int($value) ? PDO::PARAM_INT : PDO::PARAM_STR
);
}
}
I have also tried setting the third param to just be PDO::PARAM_STR
but that didn't change the behavior. 我也尝试将第三个参数设置为
PDO::PARAM_STR
但这并没有改变行为。
The server is CentOS Linux 7.3.1611
, MySQL is 5.7.17
, PHP 7.0.15
服务器是
CentOS Linux 7.3.1611
,MySQL是5.7.17
,PHP 7.0.15
PDO and MySql Extensions PDO和MySql扩展
php70w-pdo.x86_64 7.0.15-1.w7 @webtatic
php70w-mysql.x86_64 7.0.15-1.w7 @webtatic
The table is InnoDB
with UTF-8 Unicode
encoding and the collation is utf8_unicode_ci
该表是具有
UTF-8 Unicode
编码的InnoDB
,排序规则是utf8_unicode_ci
The sql connection is: sql连接为:
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
'strict' => true,
'modes' => ['STRICT_TRANS_TABLES','NO_ZERO_IN_DATE','NO_ZERO_DATE','ERROR_FOR_DIVISION_BY_ZERO','NO_AUTO_CREATE_USER','NO_ENGINE_SUBSTITUTION'],
'engine' => null,
What things can I try to resolve my issue? 我可以尝试解决什么问题?
I found the solution. 我找到了解决方案。 Our server was using the regular
php70-mysql
drivers and not the native drivers php70-mysqlnd
. 我们的服务器使用的是常规
php70-mysql
驱动程序,而不是本机驱动程序php70-mysqlnd
。 Once we updated that the integers were preserved. 一旦我们更新了整数就被保留了。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.