Error with FOUND_ROWS

I am trying to implement pagination in my search results with Yii. I have pagination working on my browse record pages, but for some reason, am having trouble with getting it working in search.

So far, I have the following SQL to produce the search results:


SELECT SQL_CALC_FOUND_ROWS DISTINCT user.id FROM user, personal_info WHERE (personal_info.bio LIKE '%a%' ) AND personal_info.user_id = user.id AND user.role = 'F' LIMIT 0, 8;

Which is passed to ActiveRecord as follows:


$results = $this->findAllBySql($sql);

Immediately afterwards I run this code:


$rows = $this->findBySql("SELECT FOUND_ROWS() as row_count;");		

echo $rows->row_count;

Strangely, I am receiving the following error when I try and execute this code:

Property "Search.row_count" is not defined.

I have pretty much exactly the same PHP code in my browse records page (but different SQL), and it works perfectly. Not sure why in this situation Yii is unable to retrieve the FOUND_ROWS value. I’ve tried running this code directly inside MySQL to see if there was something wrong with my SQL, but it retrieves the FOUND_ROWS value with no problems - this problem only happens when I try to do it inside Yii.

Any idea what I maybe doing wrong?

Many thanks!

Could be that row_count is not defined in the model?

Doh! You’re absolutely right! Thanks, was scratching my head over this for ages.