2

I have MySql Cloud Hosting,

Table(Member) - Field(id, name, balance)

when I access with Laravel on Windows machine, they are(id, balance) returned as Int,

but

when I access with Laravel on Linux machine, all field returned as String.

So this issue can make calculation operation error because they read as String. Any way to fix this issues without $casts?

Donny Gunawan
  • 363
  • 1
  • 6
  • 21
  • Please update your post with more info and some important code. I'm sure a problem is not in Windows/Linux. – Alexey Mezenin Mar 25 '16 at 10:29
  • L5+MySql+Win = return Int, L5+MySql+Linux = return String, for.ex. Member::all(); or DB::table('members')->get(); – Donny Gunawan Mar 25 '16 at 10:39
  • Possible duplicate of [PHP + PDO + MySQL: how do I return integer and numeric columns from MySQL as integers and numerics in PHP?](http://stackoverflow.com/questions/20079320/php-pdo-mysql-how-do-i-return-integer-and-numeric-columns-from-mysql-as-int) – Nick Mar 25 '16 at 11:33

2 Answers2

0

It seems a problem is in MySQL drivers. Laravel uses prepared statements by default. You have two ways: tune your Linux setup or use conversion in your code (casts or (int)).

Please look ticked answer here. You need to tune PDO::ATTR_EMULATE_PREPARES

Community
  • 1
  • 1
Alexey Mezenin
  • 158,981
  • 26
  • 290
  • 279
0

By the sounds of it, this is something to with MySQL and the drivers you're using as the other answer states.

That aside, this is a non-issue, PHP is a dynamically typed language so returning a string makes no difference unless you're running the value through is_int() which will explicitly check that it is indeed an integer. If you are doing that, don't, use is_number() instead as that handles all types.

ollieread
  • 6,018
  • 1
  • 20
  • 36