I have the same question.
Oleg:
I found a provisory solution, it's not totally efficent but it does work :-P:
http://pastebin.com/L9x96ZZs
Cheers.
I understand that it will be work, it feth all entries from table and its ok if you have not many rows in the table.
But if you have many rows in the table (for example million or more) its not good think to fetch all entries becouse it will be very big dump that will send from database server to php.
I think this solution is more correct
User::find_by_sql('SELECT count(ID) FROM users')
you can write class that extends from ActiveRecord\Model and use it for base model class
class Model extends ActiveRecord\Model
{
public static function find_num_rows()
{
return self::find('all', array('select' => 'count(*) AS num_rows'));
}
}
or this
class Model extends ActiveRecord\Model
{
public static function find_num_rows()
{
$array = self::first(array('select' => 'count(*) AS num_rows'))->attributes();
return $array['num_rows'];
}
}
That's clearly much better ;-)
)) but my think is it must be in core of the ORM
(1-9/9)
Subject: mysql_num_rows
How can i get number of rows in the table?
For example i whant to organize paging, i need to now number of rows in the table but i dont whant to select all entries becouse it can be 1000000.