Yii Create Command无法从select中获取硬编码值

时间:2017-05-29 08:09:17

标签: php mysql yii

这是我的查询

Column not found: 1054 Unknown column '"contract"' in 'field list'. The SQL statement executed was: SELECT `t`.`id`, `"contract"` AS `type` FROM `test` `t` WHERE t.company_id=1

收到此错误,

RestAPI

2 个答案:

答案 0 :(得分:0)

尝试使用避免文字名称,例如:

  $result = Yii::app()->db->createCommand()->setFetchMode(PDO::FETCH_OBJ)
    ->select('t.id,  case when 1 = 1 then 'contract' end AS type')
    ->from('test t')
    ->where('t.company_id=1')
    ->queryAll();

答案 1 :(得分:0)

使用轻微的额外更改

$result = Yii::app()->db->createCommand()->setFetchMode(PDO::FETCH_OBJ)
->select('t.id,  (case when 1 = 1 then "contract" end) AS type')
->from('test t')
->where('t.company_id=1')
->queryAll();