2

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
  • 636
  • 4
  • 14
  • 1
    Is your version of PHP able to handle numbers that large? Check the version of PHP you're using, plus if it's 64-bit or 32-bit. It's worth testing [`INT_MAX`](http://stackoverflow.com/questions/864058/how-to-have-64-bit-integer-on-php). – tadman Mar 12 '17 at 22:29
  • As I mentioned, version of PHP on computer with wrong behavior is a bit more fresh, than on another one, where everything works fine. – Rodion Baskakov Mar 12 '17 at 22:31
  • INT_MAX has value 9223372036854775807 on both computers – Rodion Baskakov Mar 12 '17 at 22:34
  • What does `echo 10203629136783381` produce? I think one installation is either broken, or 32-bit and behaving badly. – tadman Mar 12 '17 at 22:43
  • `php -r 'echo 10203629136783381;'` produces `10203629136783381`. I checked `uname -a` and it reports x86_64 architecture. The installation was made from deb-packets about a month ago. And, by the way, BIGINT values are inserted correctly into MySQL. – Rodion Baskakov Mar 12 '17 at 22:48
  • 2
    Unfortunately, only yourself can debug this one. You need to trace the steps until you find where the integer loses it's value. It can be anywhere between the PHP or in the TCP Request between PHP and MySQL. – Marco Aurélio Deleu Mar 12 '17 at 23:45
  • Can you get a log of the exact query used? – tadman Mar 13 '17 at 00:26
  • Thanks for your responses. I have finally solved the problem and posted the answer below. – Rodion Baskakov Mar 13 '17 at 10:33

1 Answers1

4

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.

Rodion Baskakov
  • 636
  • 4
  • 14