ThinkPHP6.0 Rapid Development Manual (Fallversion) / failException(链式操作20)

failException(链式操作20)

failException设置查询数据为空时是否需要抛出异常。


用于select和find方法,例如:

// 数据不存在的话直接抛出异常
Db::name('blog')
	->where('status',1)
    ->failException()
    ->select();

// 数据不存在返回空数组 不抛异常
Db::name('blog')
	->where('status',1)
    ->failException(false)
    ->select();

或者可以使用更方便的查空报错

// 查询多条
Db::name('blog')
	->where('status', 1)
    ->selectOrFail();

// 查询单条
Db::name('blog')
	->where('status', 1)
    ->findOrFail();