DB returns string instead of int (mysqlnd for PHP-

2020-04-10 18:26发布

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条回答
倾城 Initia
2楼-- · 2020-04-10 19:05

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...

查看更多
登录 后发表回答