TP的SQL语句转原生的兼容问题

浏览:415 发布日期:2017/07/08 分类:ThinkPHP5专区
例1:Db::name('xxx')->field('COUNT(IF(status=1,true,null)) as success')->find();

执行结果:SELECT COUNT(IF(status=1,`true`,null)) as success FROM `xxx` LIMIT 1

true 被自动加 `` ,报错:字段不存在!

例2:Db::name('xxx')->field('SUM(IF(type=1,score,0)) AS math, SUM(IF(type=2,score,0)) AS english')->find();

执行结果:SELECT SUM(IF(type=1,`score`,0)) AS math,SUM(IF(type=2,0)) AS english FROM `xxx` LIMIT 1

1个SUM IF 正常,2个就会被缺省掉1个字段。

其他情况下用IF语句有时候也会出现字段或参数丢失等问题。

请问怎么处理呢?
最佳答案
评论( 相关
后面还有条评论,点击查看>>