Codeigniter请求sql,但我的代码返回错误

时间:2017-08-24 22:56:46

标签: php mysql sql-server codeigniter

我希望显示SQL请求的结果,但是我的代码返回了一个我无法解析的错误。如果有人能帮助我,我会感激不尽。

我正在使用Codeigniter。

<?php defined('BASEPATH') OR exit('No direct script access allowed');

class Dropdown extends CI_Controller {

    public function __construct()
    {
        parent::__construct();  
    }

    public function index()
    {   
        $data['title']='Dependent Dropdown List';
        $data['page']='index';
        $data['MANUFACTURERS'] = $this->book_model->get_author();
        $this->load->view('index', $data);
    }


    public function ctest()
    {
        $data['MODELS'] = $this->book_model->test();
        $this->load->view('ajax_get_book',$data);
    }

}
?>

<?php defined('BASEPATH') OR exit('No direct script access allowed');

class book_model extends CI_Model {


    function __construct(){
        // Call the Model constructor
        parent::__construct();        
    }
    public function test() {   
        $lang = 6;
        $code = 533001410;

        $query = $this->db->query("SELECT DISTINCT
         IF (ART_LOOKUP.ARL_KIND IN (3, 4), BRANDS.BRA_BRAND, 
         SUPPLIERS.SUP_BRAND) AS 
         BRAND, ART_LOOKUP.ARL_SEARCH_NUMBER AS NUMBER, ART_LOOKUP.ARL_KIND,    
         ART_LOOKUP.ARL_ART_ID, DES_TEXTS.TEX_TEXT AS ART_COMPLETE_DES_TEXT
         FROM       ART_LOOKUP
         LEFT JOIN BRANDS ON BRANDS.BRA_ID = ART_LOOKUP.ARL_BRA_ID
         INNER JOIN ARTICLES ON ARTICLES.ART_ID = ART_LOOKUP.ARL_ART_ID
         INNER JOIN SUPPLIERS ON SUPPLIERS.SUP_ID = ARTICLES.ART_SUP_ID
         INNER JOIN DESIGNATIONS ON DESIGNATIONS.DES_ID = 
         ARTICLES.ART_COMPLETE_DES_ID
         INNER JOIN DES_TEXTS ON DES_TEXTS.TEX_ID = DESIGNATIONS.DES_TEX_ID
         WHERE  ART_LOOKUP.ARL_SEARCH_NUMBER = '.$code.' AND    
         ART_LOOKUP.ARL_KIND 
         IN (1, 2, 3, 4) AND    DESIGNATIONS.DES_LNG_ID = '.$lang.'
         GROUP BY   BRAND,  NUMBER");
         return $query->result();
    }
}
?>
  

错误号码:1055
  SELECT列表的表达式#3不在GROUP BY子句中,并且包含非聚合列'dpazine.ART_LOOKUP.ARL_KIND',它在功能上不依赖于GROUP BY子句中的列;这与sql_mode = only_full_group_by

不兼容      

SELECT DISTINCT IF(ART_LOOKUP.ARL_KIND IN(3,4),BRANDS.BRA_BRAND,SUPPLIERS.SUP_BRAND)AS BRAND,ART_LOOKUP.ARL_SEARCH_NUMBER作为编号,ART_LOOKUP.ARL_KIND,ART_LOOKUP.ARL_ART_ID,DES_TEXTS.TEX_TEXT AS ART_COMPLETE_DES_TEXT来自ART_LOOKUP LEFT联系品牌BRANDS.BRA_ID = ART_LOOKUP.ARL_BRA_ID关于ARTICLES.ART_ID = ART_LOOKUP.ARL_ART_ID INNER JOIN SUPPLIERS ON SUPPLIERS.SUP_ID = ARTICLES.ART_SUP_ID INNER JOIN DESIGNATIONS ON DESIGNATIONS.DES_ID = ARTICLES.ART_COMPLETE_DES_ID INNER JOIN DES_TEXTS DES_TEXTS.TEX_ID上的INNER JOIN文章= DESIGNATIONS.DES_TEX_ID,其中ART_LOOKUP.ARL_SEARCH_NUMBER ='。'533001410。' AND ART_LOOKUP.ARL_KIND IN(1,2,3,4)AND DESIGNATIONS.DES_LNG_ID ='。6。' GROUP BY    品牌,号码

     

文件名:C:/wamp64/www/CodeIgniter/system/database/DB_driver.php
    行号:691

2 个答案:

答案 0 :(得分:0)

您的GROUP BY子句不包含SELECT中的所有非聚合字段,例如ART_LOOKUP.ARL_KIND,ART_LOOKUP.ARL_ART_ID,DES_TEXTS.TEX_TEXT AS ART_COMPLETE_DES_TEXT。

请参阅此链接了解更多...

https://dev.mysql.com/doc/refman/5.7/en/group-by-handling.html

也许将这些字段添加到GROUP BY?

答案 1 :(得分:0)

您的查询没有任何问题,即mysql配置问题

<强>解决方案

  

打开my.cnf   Mysql配置文件

并将这段代码放在那里,小时问题就会解决

>>> from inspect import getfullargspec    
>>> @default_arguments
... def example(one, two, three):
...         print(one, two, three)
...

>>> getfullargspec(example)
FullArgSpec(
    args=['one', 'two', 'three'],
    varargs=None,
    varkw=None,
    defaults=('one', 'two', 'three'),
    kwonlyargs=[], kwonlydefaults=None, annotations={}
)