php - Yii1: How to use concat function in mysq like query -



php - Yii1: How to use concat function in mysq like query -

i want utilize mysql concat function in like expression. want merge firstname , lastname fullname , matched results according fullname. have tried in yii1. below code:

$criteria = new cdbcriteria(); $criteria->select = "*"; $criteria->select = 'concat(firstname , "" , lastname) fullname'; $criteria->addcondition('fullname :match'); $criteria->params = array(':match' => $query); $models = user::model()->findall($criteria);

below generated error message:

cdbcommand failed execute sql statement: sqlstate[42s22]: column not found: 1054 unknown column 'fullname' in 'where clause' (error 500) cdbcommand::fetchcolumn() failed: sqlstate[42s22]: column not found: 1054 unknown column 'fullname' in 'where clause'. sql statement executed was: select count(*) `members` `t` fullname :match.

thanks in advance

if don't need fullname afterwards, can utilize concat method in clause:

$criteria = new cdbcriteria(); $criteria->addcondition('concat(userid , " " , username) :match'); $criteria->params = array(':match' => $query); $models = user::model()->findall($criteria);

however, if want maintain fullname in select clause, can utilize alias in having clause:

$criteria = new cdbcriteria(); $criteria->select = '*, concat(userid , " " , username) fullname'; $criteria->having = 'fullname :match'; $criteria->params = array(':match' => $query); $models = user::model()->findall($criteria);

please note user model should have fullname attribute in case, otherwise won't able access fullname field.

php mysql activerecord yii yii1.x

Comments

Popular posts from this blog

php - Edges appear in image after resizing -

ios8 - iOS custom keyboard - preserve state between appearances -

Delphi change the assembly code of a running process -