Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

mysql_num_rows in laravel?

im trying to use mysql_num_rows in laravel but laravel says it not the same way like in 'raw 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:

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

like image 589
indian Avatar asked Sep 06 '16 20:09

indian


People also ask

What is mysql_ num_ rows in php?

mysql_num_rows — Get number of rows in result.

What is mysqli_ num_ rows?

The mysqli_num_rows() function returns the number of rows in a result set.

How to get number of rows in MySQL php?

We can get the total number of rows in a table by using the MySQL mysqli_num_rows() function. Syntax: mysqli_num_rows( result ); The result is to specify the result set identifier returned by mysqli_query() function.

Does laravel install MySQL?

Currently Laravel supports four database systems: MySQL, Postgres, SQLite, and SQL Server.


1 Answers

Instead of using mysql_* functions, you should use count() instead. It can be chained to Eloquent, query builder, or collections.

$users_count = DB::table('users')
     ->where('username', '=', $username)
     ->where('password', '=', $password)
     ->count();
like image 102
cmnardi Avatar answered Sep 21 '22 14:09

cmnardi