沃梦达 / 编程问答 / php问题 / 正文

DB 返回字符串而不是 int (mysqlnd for PHP-7.1/Laravel)

DB returns string instead of int (mysqlnd for PHP-7.1 / Laravel)(DB 返回字符串而不是 int (mysqlnd for PHP-7.1/Laravel))

本文介绍了DB 返回字符串而不是 int (mysqlnd for PHP-7.1/Laravel)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

几天前,我问关于我在 Laravel 中发现的一个错误的问题.

为了修复它,我在我的服务器上安装了 php5-mysqlnd.

To fix it, I installed php5-mysqlnd on my server.

今天,我将我的应用程序升级到了最新的 php 7.1.*.一切正常,除了错误又回来了,即数据库中的整数作为字符串返回,我的严格比较失败了.

Today, I upgraded my application to the latest php 7.1.*. Everything works correctly, except the bug is back again, i.e. integers in the database are returned as strings, which fails my strict comparison.

我试图为 php 7.1 找到 mysqlnd 的包,但没有(还没有?).但是 mysqlnd 似乎已启用...

I tried to find a package for mysqlnd for php 7.1 but there are none (yet?). But mysqlnd seems enabled though...

phpinfo()

PHP Version => 7.1.3-2+0~20170315222009.20+jessie~1.gbpc7e7dd
System => Linux 3.16.0-4-amd64 #1 SMP Debian 3.16.36-1+deb8u2 (2016-10-19) x86_64

mysqlnd
mysqlnd => enabled
Version => mysqlnd 5.0.12-dev - 20150407 - $Id: b396954eeb2d1d9ed7902b8bae237b287f21ad9e $

pdo_mysql
PDO Driver for MySQL => enabled
Client API version => mysqlnd 5.0.12-dev - 20150407 - $Id: b396954eeb2d1d9ed7902b8bae237b287f21ad9e $

在本地主机上输出:

"id" => 5

服务器上的输出:

"id" => "5"

"id" => "5"

1/还有什么我应该看的吗?

1/ Is there something else I should look?

2/一般来说,我应该重构我的代码以接受来自数据库的字符串而不是期待整数吗?

2/ In general, should I refactor my code to accept strings from the db instead of expecting ints?

谢谢.

推荐答案

唉,我笨!至少我今天学到了一些东西.

Sigh, I'm dumb! At least I learned something today.

phpinfo() 来自控制台的 php 版本,而不是 Apache.结果php7.1和mysqlnd没有在Apache中加载.

The phpinfo() came from the php version of the console, not Apache. Turns out php7.1 and mysqlnd was not loaded in Apache.

现在一切都很好……

这篇关于DB 返回字符串而不是 int (mysqlnd for PHP-7.1/Laravel)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:DB 返回字符串而不是 int (mysqlnd for PHP-7.1/Laravel)