Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

MarcTroesken's avatar

MySQL returning int instead of string

Hi,

am I right that MySQL usually returns int as strings ? On my forge instance it is exactly the opposite and my queries are not working anymore.

If I do:

$variable->where('foo', '1')->first();

on my local machine it works fine. But on my forge server it fails ! If I change it like so:

$variable->where('foo', 1)->first();

it works again on my production server, but not on my local machine.

So why is the return different on forge? Anyone ever had same issues ?

0 likes
6 replies
pmall's avatar

It depends on your column type and the mysql server configuration.

You have to know all bindings are escaped as strings with pdo. You must have a strang pdo or mysql configuration on your local machine

MarcTroesken's avatar

yap on my local machine all values are strings. But not on my forge server. But I didn't change anything.

pmall's avatar

yap on my local machine all values are strings

You column types ?

pmall's avatar
pmall
Best Answer
Level 56

Is $variable a collection or a query builder ?

I guess it is a collection. By default the where method use type comparison too. If you want to loosely compare the value add false as third parameter $variable->where('foo', '1', false)->first();. Or use $variable->whereLoose('foo', '1')->first();.

1 like

Please or to participate in this conversation.