codeigniter版本中的SQL查询冲突

时间:2016-03-14 05:41:38

标签: php mysql sql codeigniter

我有以下SQL查询在codeigniter版本3中完美运行 它在版本2中显示错误。

$this->db->select('*');
     if($cond!=''){
     $this->db->where($cond);
     }
     $this->db->from('(select * from products1 where pr_id  in('.implode(",",$condin).') order by pr_id asc) as a ');
     $this->db->join(PRICE_TABLE.' as b','a.pr_id=b.pr_id','inner');
     $this->db->limit($limit);
     $query=$this->db->get();
     return $query;

错误是

 A Database Error Occurred

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 'order by pr_id asc) as a) INNER JOIN `pr_product_attr_usa_new` as b ON `a`.`pr_i' at line 2

SELECT * FROM ((select * from products1 where pr_id in(752, `6263`, `542`, `2059)` order by pr_id asc) as a) INNER JOIN `pr_product_attr_usa_new` as b ON `a`.`pr_id`=`b`.`pr_id` WHERE `b`.`pr_stock` = 'yes' LIMIT 6

Filename: D:\XAMPP\htdocs\pr_sites\us\chk\system\database\DB_driver.php

Line Number: 331 

1 个答案:

答案 0 :(得分:0)

问题与代码有关:
in('.implode(",",$condin).')

输出:

 (752, `6263`, `542`, `2059)`

而不是:

 (752, `6263`, `542`, `2059`)

`符号在')之外。