-
Notifications
You must be signed in to change notification settings - Fork 11.1k
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
[5.4] DB::setFetchMode(PDO::FETCH_ASSOC) in Laravel 5.4 #17557
Comments
Check out upgrade guide (https://laravel.com/docs/5.4/upgrade):
|
@themsaid @mariomka Of course, I read this documentation use Illuminate\Database\Capsule\Manager as Capsule;
$capsule = new Capsule;
$capsule->addConnection([
'driver' => 'mysql',
'host' => 'localhost',
'database' => 'database',
'username' => 'root',
'password' => 'password',
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
]);
$capsule->setFetchMode(PDO::FETCH_ASSOC);
$capsule->setAsGlobal();
$capsule->bootEloquent(); $dispatcher = new Illuminate\Events\Dispatcher;
$dispatcher->listen(Illuminate\Database\Events\StatementPrepared::class, function ($event) {
$event->statement->setFetchMode(PDO::FETCH_ASSOC);
}); @taylorotwell Please return back |
Would be so much easier just to keep the god damn setter, why even have the protected var and then a getter for it - but no way of setting it except hacking the source or setting up event listeners? Retarded. Simply retarded, no way around it. |
It's not intended for people to try to change this setting anymore. |
This does not work for me neither:
Can you put an example of how implement the listener please |
Another downside of needing to set the fetch mode via event listener, you lose it when mocking events in unit tests. Currently event mocking is all or nothing, as soon as you want to mock and test one event, your new |
@GrahamCampbell Can you please expand on why it is no longer intended for people to change the fetch mode? If we are no longer supposed to, why is it mentioned in the docs that you CAN keep using You took something simple and flexible, a config value or a public setter, and made it inflexible and problematic (the event listener method breaks when mocking events in tests). Why? |
Causing me some headaches too. +1 for bring it back. |
Added proposal to laravel/ideas#546 for some hopeful feedback. |
For me the FETCH_ASSOC mode allows for a much simpler and far more resource efficient way to export large chunks of data into Excel. It's a useful feature, not often used but worth keeping around. |
I just want to drop it for this reason. |
$capsule = new Capsule(); |
Eloquent is used outside of Laravel. Also, how in the hell is this an issue, why remove something that is common, worked, and obviously affects people? |
This is what I do
I don't agree with the author. The |
Removing this was so evil. Many hours of unnecessary work for everybody that want to upgrade code that used this. |
Let's hear it for a rewind! |
Коллеги, вы все ищите решение проблемы, а кто нибудь знает почему был выбран такой режим выборки.Colleagues, you all are looking for a solution to the problem, and who knows why this selection mode was chosen. |
What I don't understand is that there are methods native to Laravel that will reject PDO objects and demand an array. Specifically class DB. Why demand array if you are going make it next to impossible to let us give you one. |
Yeah, it really sucks. We're migrating a legacy system into a new project and we're working with very large sets of data and we need to do an extra step to convert that pdo object into an array because DB::insert won't work with objects... a totally unneeded step, for every record we grab from the database.... I roll my eyes every time I think of this.... |
what we talk about earlier is how to achieve the goal whithout modifying the library code
…------------------ Original ------------------
From: Debanjan Ganguly <[email protected]>
Date: Tue,Oct 1,2019 1:52 PM
To: laravel/framework <[email protected]>
Cc: Frost Wong <[email protected]>, Comment <[email protected]>
Subject: Re: [laravel/framework] [5.4] DB::setFetchMode(PDO::FETCH_ASSOC) in Laravel 5.4 (#17557)
Theres another option I find to by pass it
Add env DB_FETCHMODE=FETCH_ASSOC
In config/database add for connections.mysql 'fetch_mode' => env('DB_FETCHMODE', 'FETCH_ASSOC'),
In illuminate/datbase/connection.php replace prepared function with
protected function prepared (PDOStatement $statement){ $config = $this->config; $statement->setFetchMode($config['fetch_mode'] == "FETCH_OBJ" ? 5 : ($config['fetch_mode'] == "FETCH_NUM" ? 3 : 2)); $this->event(new Events\StatementPrepared( $this, $statement )); return $statement; }
This make default FETCH_ASSOC for your application
Then if you want to change it like before,
add config(['database.connections.mysql.fetch_mode' => 'FETCH_OBJ']);
a replacement of DB::setFetchMode(PDO::FETCH_ASSOC);
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub, or mute the thread.
|
Theres another option I find to by pass it This make default FETCH_ASSOC for your application Then if you want to change it like before, |
@lovelock If laravel official don't return it back to us, we have to bypass it. And how should you do it without modifying library code a little. What I did was just passing PDO fetch method to config data and achieve the same thing dynamically |
We can use event listener as I metioned before. The problem of modifying the library code is upgrading the packge. What I don’t understand is why there is nobody send pr to this issue 😂
…------------------ Original ------------------
From: awesomedeba10 <[email protected]>
Date: Tue,Oct 1,2019 2:00 PM
To: laravel/framework <[email protected]>
Cc: Frost Wong <[email protected]>, Mention <[email protected]>
Subject: Re: [laravel/framework] [5.4] DB::setFetchMode(PDO::FETCH_ASSOC) in Laravel 5.4 (#17557)
@lovelock If laravel official don't return it back to us, we have to bypass it. And how should you do it without modifying library code a little. What I did was just passing PDO fetch method to config data and achieve the same thing dynamically
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub, or mute the thread.
|
Any news for Laravel 6
…On Tue, Oct 1, 2019 at 1:33 AM Frost Wong ***@***.***> wrote:
We can use event listener as I metioned before. The problem of modifying
the library code is upgrading the packge. What I don’t understand is why
there is nobody send pr to this issue 😂
------------------ Original ------------------
From: awesomedeba10 ***@***.***>
Date: Tue,Oct 1,2019 2:00 PM
To: laravel/framework ***@***.***>
Cc: Frost Wong ***@***.***>, Mention <
***@***.***>
Subject: Re: [laravel/framework] [5.4] DB::setFetchMode(PDO::FETCH_ASSOC)
in Laravel 5.4 (#17557)
@lovelock If laravel official don't return it back to us, we have to
bypass it. And how should you do it without modifying library code a
little. What I did was just passing PDO fetch method to config data and
achieve the same thing dynamically
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub, or mute the thread.
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#17557?email_source=notifications&email_token=AKPGZDPWIZOXZQEDNQGAJTDQMLVMZA5CNFSM4C5YUNJKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEAAEPVY#issuecomment-536889303>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AKPGZDKSMRQIY7WWIQ6PTJTQMLVMZANCNFSM4C5YUNJA>
.
|
@JustinLawrenceMS actually its still same as of laravel 6, and the code I provide, it was in laravel 6.0.4 latest as of now |
Can anyone tell the reason why setFetchMode is removed from laravel? |
Hi any update? |
This is what I’m doing to get my associative array.
$x = DB::select($sql);
$assoc = json_decode(json_encode($x), true);
dd($assoc);
…On Wed, Sep 16, 2020 at 2:57 AM kmacute ***@***.***> wrote:
Hi any update?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#17557 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AKPGZDIFN3YILDJBC52TXTTSGBVYNANCNFSM4C5YUNJA>
.
|
Hey everyone, I'm locking this issue because it either has gone off-topic, become a dumping ground for things which shouldn't be in an issue tracker or is just too old. Please try to discuss things further on one of the below channels: |
$capsule->setFetchMode(PDO::FETCH_ASSOC); not working? return object
prompt. is now set FetchMode if the database is used not laravel?
The text was updated successfully, but these errors were encountered: