2019年1月

MYSQL5.7版本sql_mode=only_full_group_by问题

错误信息
`SQLSTATE[42000]: Syntax error or access violation: 1055 Expression #3
of SELECT list is not in GROUP BY clause and contains nonaggregated column
'iicityYii.opportunity_conditions.money' which is not functionally dependent
on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by`

  1. 查看 sql_mode
    select @@global.sql_mode
  2. 去掉 ONLY_FULL_GROUP_BY
    set @@global.sql_mode ='STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION';

或者:
SET GLOBAL sql_mode=(SELECT REPLACE(@@sql_mode,'ONLY_FULL_GROUP_BY',''));

或者,修改mysql配置文件,新增
[mysqld]
sql-mode=""

ThinkPHP5 自定义模版标签tablib

ThinkPHP5 自定义模版标签tablib

新建文件application/common/taglib/Diy.php
Diy.php

<?php
// +----------------------------------------------------------------------
// | 自定义模版标签
// +----------------------------------------------------------------------
// | Author: SenSen <1050575278> 2018-12
// +----------------------------------------------------------------------
namespace app\common\taglib;

use think\Db;
use think\template\TagLib;

class Sen extends TagLib
{
    protected $tags = [
        'arclist' => ['attr'=> 'field,id,limit,cid,order,name,flag,type', 'close'=>1],
        'show' => ['attr'=> 'title,field', 'close'=>0],
    ];

    /**
     * 文章标签
     * @param $tag
     * @param $content
     * @return string
     */
    public function tagArclist($tag, $content)
    {
        $id = isset($tag['id']) ? $tag['id'] : 'vo';
        $order = empty($tag['order']) ? "'id DESC'" : '"'.$tag['order'].'"';
        $name = 'article';
        $field = "''";
        if (!empty($tag['field'])) {
            if (strpos($tag['field'], '$') === 0) {
                $field = $tag['field'];
                $this->autoBuildVar($field);
            } else {
                $field = "'{$tag['field']}'";
            }
        }
        $cid = "''";
        if (!empty($tag['cid'])) {
            if (strpos($tag['cid'], '$') === 0) {
                $cid = $tag['cid'];
                $this->autoBuildVar($cid);
            } else {
                $cid = "'{$tag['cid']}'";
            }
        }
        $flag = "''";
        if (!empty($tag['flag'])) {
            if (strpos($tag['flag'], '$') === 0) {
                $flag = $tag['flag'];
                $this->autoBuildVar($flag);
            } else {
                $flag = "'{$tag['flag']}'";
            }
        }
        $type = "''";
        if (!empty($tag['type'])) {
            if (strpos($tag['type'], '$') === 0) {
                $type = $tag['type'];
                $this->autoBuildVar($type);
            } else {
                $type = "'{$tag['type']}'";
            }
        }
        $limit = "''";
        if (!empty($tag['limit'])) {
            if (strpos($tag['limit'], '$') === 0) {
                $limit = $tag['limit'];
                $this->autoBuildVar($limit);
            } else {
                $limit = "'{$tag['limit']}'";
            }
        }else{
            $limit = '0,6';
        }
        $parse = <<<parse
<?php
    \$$name = \app\common\model\Article::tagArticle([
    'field'   => {$field},
    'cid'=>{$cid},
    'limit'=>{$limit},
    'flag'=>{$flag},
    'type'=>{$type},
    'order'=>{$order}
]);
?>
{volist name="{$name}" id="{$id}"}
{$content}
{/volist}
parse;
        return $parse;
    }

    /**
     * 广告标签
     * @param $tag
     * @return mixed
     */
    public function tagShow($tag)
    {
        $title = $tag['title'] ? $tag['title'] : '';
        $result = Db::name('ad')->where(['tag'=>$title, 'status'=>1])->find();
        return $result['content'];
    }

}

- 阅读剩余部分 -