Created
December 14, 2017 17:07
-
-
Save MatteoOreficeIT/716336b4cf5e2ae5e981457dbd6a4926 to your computer and use it in GitHub Desktop.
Laravel change PDO setFetchMode
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace App\Providers; | |
use Illuminate\Support\Facades\Event; | |
use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider; | |
class EventServiceProvider extends ServiceProvider | |
{ | |
/** | |
* The event listener mappings for the application. | |
* | |
* @var array | |
*/ | |
protected $listen = [ | |
'App\Events\Event' => [ | |
'App\Listeners\EventListener', | |
], | |
]; | |
/** | |
* Register any events for your application. | |
* | |
* @return void | |
*/ | |
public function boot() | |
{ | |
parent::boot(); | |
Event::listen(StatementPrepared::class, function ($event) { | |
if(self::$fetchMode) | |
$event->statement->setFetchMode(self::$fetchMode); | |
}); | |
} | |
//\PDO::FETCH_ASSOC | |
protected static $fetchMode = null; | |
/** | |
* @return int | |
*/ | |
public static function getFetchMode() | |
{ | |
return self::$fetchMode; | |
} | |
/** | |
* @param int $fetchMode | |
*/ | |
public static function setFetchMode($fetchMode) | |
{ | |
self::$fetchMode = $fetchMode; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment