How to count rows in Nette Database?

Notice: This thread is very old.
alfanumeric
Member | 2
+
0
-

Hello, how can I get number of results from query?

$q = $this->database->query('SELECT * FROM post WHERE ID = ?', $id);

I don't understand your API but I found only this:

$q->count

Cannot read an undeclared property Nette\Database\ResultSet::$count.

And

count($q)

= 1 all times.

Last edited by alfanumeric (2015-07-05 21:17)

besanek
Member | 128
+
+1
-

Try this:

$q->getRowCount();
alfanumeric
Member | 2
+
0
-

Thank you very much. Why this is not specified in the API?

mrtnzlml
Member | 140
+
0
-

Yes, it is: https://api.nette.org/…sultSet.html#…. This API should be more important for you.

Šaman
Member | 2634
+
0
-

There are Nette\Database\Table\Selection and Nette\Database\ResultSet
Most of examples show rich Nette\Database\Table, but you use simple query and that function returns ResultSet.