How to get rowCount from table?

6 months 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?

6 months ago

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)

6 months ago

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