zoukankan      html  css  js  c++  java
  • laravel group by 42000

    sql 分组查询异常:

    sql error:

    SQLSTATE[42000]: Syntax error or access violation: 1055 Expression #2 of SELECT list is not in GROUP BY clause and contains nonaggr

    连接数据时候使用了 ONLY_FULL_GROUP_BY 模式,下面是两种处理方式

    1 , database.php  strict 关闭

    strict=>false,

    2 , 设置连接具体模式,strict 下添加 modes

     

    strict=>true,
    'modes'          => [
        'STRICT_TRANS_TABLES',
        'NO_ZERO_IN_DATE',
        'NO_ZERO_DATE',
        'ERROR_FOR_DIVISION_BY_ZERO',
        'NO_AUTO_CREATE_USER',
        'NO_ENGINE_SUBSTITUTION'
    ],
    larave 连接mysql源码片段
    /**
         * Set the modes for the connection.
         *
         * @param  PDO  $connection
         * @param  array  $config
         * @return void
         */
        protected function setModes(PDO $connection, array $config)
        {
            if (isset($config['modes'])) {
                $this->setCustomModes($connection, $config);
            } elseif (isset($config['strict'])) {
                if ($config['strict']) {
                    $connection->prepare($this->strictMode($connection))->execute();
                } else {
                    $connection->prepare("set session sql_mode='NO_ENGINE_SUBSTITUTION'")->execute();
                }
            }
        }

    参考来源:

    https://learnku.com/articles/6087/laravel-database-the-startup-and-connection-of-database-services

  • 相关阅读:
    关于正则表达式
    hashilib模块和hmac模块
    PyYAML模块和ConfigParser模块
    xml处理模块
    shutil模块(文件,文件夹,压缩包处理)
    十四、浏览器检测
    十三、BOM
    十二、匿名函数和闭包
    并发,并行,同步,异步的区别
    java中常见的类,接口,包,异常
  • 原文地址:https://www.cnblogs.com/heheisme/p/11497387.html
Copyright © 2011-2022 走看看