Laravel 中的 mysql_num_rows?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/39357144/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
mysql_num_rows in laravel?
提问by indian
im trying to use mysql_num_rows in laravel but laravel says it not the same way like in 'raw php'
我试图在 Laravel 中使用 mysql_num_rows 但 Laravel 说它与“原始 php”中的方式不同
example:
例子:
$users = DB::table('users')
->where('username', '=', $username)
->where('password', '=', $password)
->get();
what i want to do:
我想做的事:
$count = mysql_num_rows($users);
if($count > 0 ){
$user->login = $request->login;
$user->email = $request->email;
$user->password = $request->password;
Auth::login($user);
return redirect("/");
}else{
return "datos incorrectos";
}
what laravel says:
什么 laravel 说:
Call to undefined function App\Http\Controllers\Auth\mysql_num_rows()
PD: its not philosophy of code just make commets about that question, i dont want answers like "u gonna crypt that thing?", "why not use [insert my faborite ORM]" is just a simple question THANKS
PD:它不是代码哲学只是对那个问题提出意见,我不想要诸如“你要加密那个东西?”、“为什么不使用 [插入我的制造商 ORM]”之类的答案只是一个简单的问题谢谢
回答by cmnardi
Instead of using mysql_* functions, you should use count()
instead. It can be chained to Eloquent, query builder, or collections.
与其使用 mysql_* 函数,不如使用它count()
。它可以链接到Eloquent、查询构建器或集合。
$users_count = DB::table('users')
->where('username', '=', $username)
->where('password', '=', $password)
->count();