DB returns string instead of int (mysqlnd for PHP-7.1 / Laravel)

一笑奈何 提交于 2019-12-02 00:01:13

问题


A few days ago, I asked a question about a bug I found in Laravel.

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

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.

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 $

Output on localhost:

"id" => 5

Output on server:

"id" => "5"

1/ Is there something else I should look?

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

Thank you.


回答1:


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

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

Everything is fine now...



来源:https://stackoverflow.com/questions/42862620/db-returns-string-instead-of-int-mysqlnd-for-php-7-1-laravel

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!