这是我的查询
$result = Yii::app()->db->createCommand()->setFetchMode(PDO::FETCH_OBJ)
->select('t.id, "contract" AS type')
->from('test t')
->where('t.company_id=1')
->queryAll();
我收到此错误,
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
最佳答案
尝试使用避免文字名称,例如:
$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();
关于php - Yii Create Command 无法从 select 获取硬编码值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44237540/