How to get rowCount from table?

Bill Lions
Member | 47
+
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?

manwe
Member | 44
+
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)

David Matějka
Moderator | 6445
+
+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