CDbCriteria param variable type


let me first explain the problem. I was performing a findAll query using criteria object.

The query is about fetching some apartments. Everything was working fine but when I added the parameter for number of rooms there were suddenly no results.

Now, this may be a PDO question more then Yii but perhaps not.

What I found through debugging is that the problem was with that number of rooms parameter was bound as ‘string’.

When I typecasted it as (int) $rooms the query returned results.

Maybe I wouldn’t be surprised with this if there weren’t two other params: both numbers but one bound as string and the other as integer. And the one bound as string is actually a primary key in joined table.

Can anyone please explain what is going on here?

Hi, can you paste your code?

Hi, sorry for late response.

I can’t paste all the code 'cause there’s lots of criteria but here are the important parts:

$criteria = new CDbCriteria();

$criteria->alias = 'au';

$criteria->join = "LEFT JOIN accommodation_objects accObject ON = au.acc_object_id " .

    "LEFT JOIN locations_countries lc ON = accObject.country_id ";

$criteria->addCondition(" = :cid");

$criteria->params[':cid'] = $countryId;

$criteria->addCondition(' = :active');

$criteria->params[':active'] = 1;

// Number of rooms

$criteria->join .= " LEFT JOIN unit_fields_values ufv ON ufv.unit_id = ";

$criteria->addCondition("ufv.field_id = 2 AND ufv.value >= :rooms ");

$criteria->params[':rooms'] = $ids['filters']['rooms'];

When debuged :cid is bound as string, :active as integer and :rooms as string and there are no results.

But when the last line is changed to

$criteria->params[':rooms'] = (int) $ids['filters']['rooms'];

then it works.