php - Codeigniter 版本冲突中的 SQL 查询

标签 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 

最佳答案

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

输出:

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

而不是:

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

` 符号位于 ')' 之外。

关于php - Codeigniter 版本冲突中的 SQL 查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35980264/

相关文章:

javascript - PHP 验证和 Javascript 验证不能一起工作

php - CURL - 错误代码 : 6 Couldn't resolve host 'http://www.yahoo.com' - XAMPP

php - 在mysql中选择细节

mysql - 使用 COUNT 并将两列的值加在一起

SQL 四舍五入到小数点后两位问题

php - 点击时动态添加输入,但有一个 while 循环

Javascript fadeTo 递增

PHP 在 SQL 语句中转换日期时间

php - 寻找共同的数据集和旅程路径

mysql组号使用多次并增加总成本