1x0's avatar
Level 1

Eloquent passes values as strings instead of integers

Hi all,

Does anyone know why a query like this: DB::table('test')->select('id')->where('user_id', '=', 1)->first(); Results in: SELECT id FROM test WHERE user_id='1' LIMIT 1; 'user_id' is of the type INT in the database, so why does Eloquent add quotes to the value?

However, the quotes disappear when I write it like this: DB::table('test')->select('id')->where('user_id', '=', DB::raw(1))->first(); Or like this: DB::table('test')->select('id')->whereRaw('user_id = 1')->first();

Does anyone have a clue why it behaves like this?

0 likes
4 replies
1x0's avatar
Level 1

Hi Cronix,

That's what I thought as well. However, "PDO::ATTR_STRINGIFY_FETCHES" has already been set to false. :(

Cronix's avatar

What about PDO::ATTR_EMULATE_PREPARES? There are a few options mentioned on that page, as well as different php drivers to use (php-mysqlnd vs php-mysql), etc.

1x0's avatar
Level 1

I'm using the same values as shown in the Stackoverflow thread: PDO::ATTR_CASE => PDO::CASE_NATURAL, PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, PDO::ATTR_ORACLE_NULLS => PDO::NULL_NATURAL, PDO::ATTR_STRINGIFY_FETCHES => false, PDO::ATTR_EMULATE_PREPARES => false,

However, that thread seems to suggest that MySQL is returning int's as strings, which is not really the issue that I'm having. The issue that I have is that Eloquent seems to make strings of all values in the WHERE clause (e.g. WHERE id='5' instead of WHERE id=5).

Anyway, I'll try to set the driver to mysqlnd on another server to see if it makes a difference.

Thanks.

Please or to participate in this conversation.