Codeigniter导致mysql语法错误

时间:2015-03-17 02:33:19

标签: php mysql sql codeigniter

我想检查r.is_show_map = 1,如果为true,则返回r.lat,否则返回null

这是代码

  $this->db->select('r.*, IF(r.is_show_map = 1, r.lat, null) as r.lat', false);

问题是它导致了语法错误

Error Number: 1064

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '.lat FROM (`request` as r) WHERE `r`.`adv_type` != 0 AND `r`.`is_delete` = 0 AN' at line 1

SELECT r.*, IF(r.is_show_map = 1, r.lat, null) as r.lat FROM (`request` as r) WHERE `r`.`adv_type` != 0 AND `r`.`is_delete` = 0 AND NOW() <= DATE_ADD(r.create_date, INTERVAL 15 DAY)

如何解决?感谢

1 个答案:

答案 0 :(得分:1)

试试这个:

$this->db->select('r.*, IF(r.is_show_map = 1, r.lat, null) as lat', false);