Skip to content
Advertisement

fetchall returns stdClass object in laravel

I’m executing a query to a db2 ibm database in Laravel.

JavaScript

The problem is that the fetchAll() returns an array of stdClass object.

JavaScript

That’s nice and all, but I’d rather get an array instead. I have to send the data through a http request and unfortunately, the data received at the other end of the request returns as a stream.

So how do I make fetchAll return an array instead of an stdObject class ?

I have tried to edit the options in the database.php file in laravel as such:

JavaScript

But it still gives me the exact same result.

This is my code to fetch the data in laravel:

JavaScript

Advertisement

Answer

It seems the problem was the encoding on special characters causing syntax errors and thus invalid formatted json. I have made it to work by converting to utf8 encoding and then a json_decode instead of encode.

JavaScript

And then in my response:

JavaScript
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement