From 9023041e6b299db71f662b58c45e10d7885f68a5 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Sun, 12 Jun 2016 12:53:06 +0800 Subject: [PATCH] =?UTF-8?q?Query=E7=B1=BB=E5=A2=9E=E5=8A=A0findOrFail=20se?= =?UTF-8?q?lectOrFail=E5=BF=AB=E6=8D=B7=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/db/Query.php | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/library/think/db/Query.php b/library/think/db/Query.php index eaa90e5d..43cfd300 100644 --- a/library/think/db/Query.php +++ b/library/think/db/Query.php @@ -1782,6 +1782,34 @@ class Query return $data; } + /** + * 查找多条记录 如果不存在则抛出异常 + * @access public + * @param array|string|Query|\Closure $data + * @return array|\PDOStatement|string|Model + * @throws DbException + * @throws Exception + * @throws PDOException + */ + public function selectOrFail($data=[]) + { + return $this->failException(true)->select($data); + } + + /** + * 查找单条记录 如果不存在则抛出异常 + * @access public + * @param array|string|Query|\Closure $data + * @return array|\PDOStatement|string|Model + * @throws DbException + * @throws Exception + * @throws PDOException + */ + public function findOrFail($data=[]) + { + return $this->failException(true)->find($data); + } + /** * 分批数据返回处理 * @access public