I have a table with around 700,000 rows.
Profile::model()->findAll("country='US'")
I used this to find all rows that have 'US' as its country. But the execution stopped and I didn't get any result. But then I added limit like below
Profile::model()->findAll("country='US' limit 10000")
then it worked.
why the execution stopped? Please help me.. I'm new to YII.
If you use
findAll
, then all records will be returned without any limit applied. However,CActiveDataProvider
automatically paginates results if you don't tell it otherwise. As mentioned in the comments, you are likely running out of memory when usingfindAll
. Using a limit or pagination (which automatically applies a limit) lowers the returned number of rows to what your application can handle.I recommend using CDataProviderIterator to fetch large numbers of active records. Try the following sample code.
Using the iterator, Yii will automatically fetch just 10000 records (a number you say worked without running out of memory) at a time, and then remove them from memory before grabbing the next page. Conveniently all the records can be accessed with a
foreach
loop without any further work from you.Change the 10000 value as necessary to achieve desired results. Also, make sure you are monitoring your error logs to identify out of memory and other errors.