Strange behavior with BIGINT in Laravel or PHP

Rodion Baskakov

I have tables (MySQL) with lots of BIGINT values in them. And I have 2 computers where PHP code (based on Laravel framework) runs, getting values from those tables. On one machine (Mac OS) everything works fine, but another one (Debian jessie) makes me mad. The problem is, I can't use BIGINT values in queries. Here are a couple of examples of what I'm talking about:

Client::where('client_id', 10203629136783381)->first(); — returns null Client::where('client_id', '10203629136783381')->first(); — returns correct result

\DB::select('SELECT * FROM clients WHERE client_id=?', [10203629136783381]) — returns an empty array

\DB::select('SELECT * FROM clients WHERE client_id=10203629136783381') — returns correct result

If I just run a query directly in MySQL-client using BIGINT value as it is, not as a string, the query works fine.

I don't know how to fix this behavior and make my code understand BIGINT values. Both computers have 64bit architecture, PHP version is 5.6.29 on Mac and 5.6.30 on Debian.

Rodion Baskakov

Well, after several hours of reading docs and experimenting with PDO and Eloquent I found a difference between mysql-extentions used by PHP on the computers. PHP on my Mac OS uses php56-mysqlnd and PHP on my server used regular php5-mysql. I have just replaced it with php5-mysqlnd and now everything works great on both computers. Hope, this information will be useful for someone else, who may get stuck with such unexplainable behavior of PDO (and Eloquent, which uses PDO). I still can't get the reason the old driver worked that way, but I'm happy to leave this issue behind my back.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

TOP Ranking

HotTag

Archive