Answer the question
In order to leave comments, you need to log in
How to properly organize a query with compare in Yii?
Hey!
What am I doing wrong?
I need to get a request like this:
SELECT COUNT(*) FROM `t_product` `t` WHERE EXIST=:ycp0 AND CAT=:ycp1
AND
(NAME LIKE :ycp2 OR NAME_EN LIKE :ycp3 OR NAME_EXCEL LIKE :ycp4 OR NAME_MENU LIKE :ycp5)
$criteria->compare('EXIST','1');
$criteria->compare('CAT','0');
$criteria->compare('NAME',$search->string,true,'AND');
$criteria->compare('NAME_EN',$search->string,true,'OR');
$criteria->compare('NAME_EXCEL',$search->string,true,'OR');
$criteria->compare('NAME_MENU',$search->string,true,'OR');
Answer the question
In order to leave comments, you need to log in
$connection = Yii::app()->db;
$sql = "
SELECT COUNT(*) FROM `t_product` `t` WHERE EXIST=:ycp0 AND CAT=:ycp1
AND
(NAME LIKE :ycp2 OR NAME_EN LIKE :ycp3 OR NAME_EXCEL LIKE :ycp4 OR NAME_MENU LIKE :ycp5)
";
$dataReader = $connection->createCommand($sql)->query();
$rows = $dataReader->readAll();
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question