How to get rowCount from table?

about a month ago

Bill Lions
Member | 19
+
0
-

How do I get the number of rows in a database table?
I see rowCount() but how to implement?

$row_count = $this->database->table('my_table')->getRowCount();

Is this correct?

about a month ago

manwe
Member | 39
+
0
-

Hey Bill,
try
$this->database->table('my_table')->count(); if you're using Nette\Database

Last edited by manwe (2019-03-19 07:45)

about a month ago

David Matějka
Moderator | 5852
+
+4
-

you should use ->count('*') instead of ->count(). first one directly executes COUNT() sql query. the second one selects all rows and counts them using php count