【发布时间】:2016-11-25 16:49:00
【问题描述】:
我想根据某些条件将where 子句附加到查询中,问题是我检查它是否从数据库返回一行的方式总是返回true。
如果我像这样在一行中进行查询:
$test= DB::table('users')->where('email', $email)->where('password', $password)->first();
它按预期工作,如果找到一行它是真的,反之亦然,但如果我像这样附加到查询中,它总是正确的(这是有道理的,但我如何检查它是否真的从数据库?):
$test= DB::table('users');
$test->where('email', $email);
$test->where('password', $password);
$test->first();
if ($test) {
// always true
}
【问题讨论】:
-
$test为空的情况下究竟包含什么? -
@Don'tPanic 不错!
标签: php mysql laravel-5 fluent