lumen框架pdo返回数组格式

lumen5.5(5.4?忘了),默认返回的数据格式是对象不再返回数组形式,config/database.php中设置了也没用。

 

1、新建一个EventServiceProvider.php文件

class EventServiceProvider extends ServiceProvider {
	/**
	 * The event listener mappings for the application.
	 *
	 * @var array
	 */
	protected $listen = [
	];
	public function boot() {
        //监听事件
		Event::listen ( StatementPrepared::class, function ($event) {
			$event->statement->setFetchMode(\PDO::FETCH_ASSOC);
		});
    }
}

2、在app.php中注册

$app->register(\GouuseCore\Providers\EventServiceProvider::class);

\GouuseCore\Providers\是我自己的命名空间

你可能感兴趣的:(lumen)