findAll crashes

Hi all,

First of all thanks for checking this post out.

I use Yii 1.1.12 and I have an issue with one call to findAll. The code looks like this:

$sql = ‘provider_id=’ . $this->provider->provider_id;

$items = Item::model()->findAll($sql, array());

the findAll crashes and the response goes out empty.if I put echo’s around find all the one before it returns and the one after it does not.

The table of items is quite large, so it might be related.

I think so especially because it works if I change the $sql like this:

$sql = array(‘condition’ => ‘provider_id=’ . $this->provider->provider_id, ‘limit’ => 1000, ‘order’ => ‘id desc’);

Many thanks in advance


In the case where it does not work, you set $sql to a string, and in the case where it works, you set it to an array. Might that not be related?

for first scenario it should be like this :

$sql = ‘provider_id=’ . $this->provider->provider_id;

$items = Item::model()->findAll(['condition = '.$sql);

check docs CActiveRecord.findAll

1 Like

You’re probably running out of memory. Active record can be a bit demanding because it returns much more than just your selected table columns. You could try limiting the columns being selected to reduce the footprint, adn/or resort to lazy loading if you are eager-pulling in too many relations.

Is there a reason why you need to load all data at once and not just paginate it?

Thanks for replying.

I tried using an array, doesn’t help unfortunately.

Thanks georaldc, looks like it’s indeed the case. I’ll do pagination.