E
E
EVOSandru62015-01-16 12:37:41
MySQL
EVOSandru6, 2015-01-16 12:37:41

Why doesn't CDbCritaria fulfill more than one condition in Yii?

$criteria = new CDbCriteria();
This option works: This one works too But this one doesn't, returns an empty result, although there are definitely values ​​in the table that satisfy the WHERE condition
$criteria->condition = " `LEVEL` = '2'";
$criteria->condition = " `EXIST` = '1'";

$criteria->condition = " `LEVEL` = '2' AND `EXIST` = '1' ";

I send the criterion as it should be in findAll ()
$ob = Service::model()->findAll($criteria);
I intentionally make a mistake in the word EXIST
It turns out:
SELECT * FROM `t_service` `t` WHERE `LEVEL` = '2' AND `EIST` = '1'

What could be the reason?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
E
Eugene, 2015-01-16
@EVOSandru6

$criteria->condition
overwrites the previous condition and sets a new one, you need to use
$criteria->addCondition()

M
melnikov_m, 2015-01-16
@melnikov_m

Try using $criteria->compare();

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question