Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Eloquent 5.4.0 removes/breaks $connection->setFetchMode() #17728

Closed
innobrig opened this issue Feb 2, 2017 · 5 comments
Closed

Eloquent 5.4.0 removes/breaks $connection->setFetchMode() #17728

innobrig opened this issue Feb 2, 2017 · 5 comments

Comments

@innobrig
Copy link

innobrig commented Feb 2, 2017

  • Laravel Version: N/A (using Eloquent without Laravel)
  • Eloquent Version: 5.4.0
  • PHP Version: 7.0

Description:

In Eloquent 5.3.23 the following code worked:

    $fetchMode = \PDO::FETCH_ASSOC;
    $sql = "SELECT * FROM some_table";
    $dbConn = \Illuminate\Database\Capsule\Manager::connection();
    $dbConn->setFetchMode ($fetchMode);
    $data = $dbConn->select ($sql);

Steps To Reproduce:

In Eloquent version 5.4.0 the above code produces the following error:

Call to undefined method Illuminate\Database\MySqlConnection::setFetchMode() 

I've looked at the code and it's not quite clear to me how to achieve the previously working/supported behavior using version 5.4.0.

@RikSomers
Copy link

RikSomers commented Feb 2, 2017

Hi,

This is documented in the Laravel 5.4 upgrade guide (Search for "Fetch Mode").

The ability to customize the fetch mode is removed and is defaulted to PDO::FETCH_OBJ. You can override this by using an event listener, as stated in the upgrade guide:

Event::listen(StatementPrepared::class, function ($event) {
    $event->statement->setFetchMode(...);
});

Not sure how to fix it without using (more) laravel components tho.

Also see #17557

@innobrig
Copy link
Author

innobrig commented Feb 2, 2017

Not sure how to fix it without using (more) laravel components tho.

If this is impossible (or even quite difficult) to do without additional Laravel components, then I would humbly suggest that this is not a good change. Not everybody (myself included) uses Eloquent with Laravel and the ability to easily integrate with non-Laravel codebases is an important factor for a framework like Eloquent.

@RikSomers
Copy link

Well, the only additional component you really would need would be the event listener, but I agree it's not the most elegant solution. But the laravel team probably has a good reason to remove the option.

@innobrig
Copy link
Author

innobrig commented Feb 2, 2017

Yeah, I've adapted my code to convert the resulting object to an array manually. Not as elegant but it works. Thanks :-)

@raveren
Copy link

raveren commented Mar 25, 2019

wow, closed issue, booo!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants