failException

failException設(shè)置查詢數(shù)據(jù)為空時是否需要拋出異常,如果不傳入任何參數(shù),默認(rèn)為開啟,用于selectfind方法,例如:

// 數(shù)據(jù)不存在的話直接拋出異常
Db::name('blog')
	->where(['status' => 1])
    ->failException()
    ->select();
// 數(shù)據(jù)不存在返回空數(shù)組 不拋異常
Db::name('blog')
	->where(['status' => 1])
    ->failException(false)
    ->select();

或者可以使用更方便的查空報錯

// 查詢多條
Db::name('blog')
	->where(['status' => 1])
    ->selectOrFail();

// 查詢單條
Db::name('blog')
	->where(['status' => 1])
    ->findOrFail();
文檔最后更新時間:2018-04-26 09:48:28

文檔
目錄

深色
模式

切換
寬度