Spimes 主题魔改之互动读者兼容 MySQL 5.7 +

Typecho教程 2020-04-30 80℃ 0 0

需求

刚到手就发现 Spimes主题不能用互动读者。

SQLSTATE[42000]: Syntax error or access violation: 1055 Expression #3 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'xmp.xmp_comments.authorId' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by

说真的,对于不兼容 MySQL 8 这件事,搞得我对这个主题都没什么兴趣了。我们公司一破国企都主用 MySQL 8了现在。

解析

解决方式有两个,一个是关闭只允许 Full Group By,另一个方法就是规范SQL查询语句,我选择当然是规范SQL查询语句啊。

代码

把SQL查询语句改成下面这个就行

Typecho_Db::get()
            ->select('count(author) AS count', 'mail', 'any_value(author) as author', 'any_value(authorId) as authorId')
            ->from('table.comments')
            ->where('created > ?', $period)
            ->where('status = ?', 'approved')
            ->where('type = ?', 'comment')
            ->group('mail')
            ->order('count', Typecho_Db::SORT_DESC)
            ->limit(4);

后记

同时顺带一提这主题说是显示30天内互动最多的读者,结果代码里时间写错了

评论 (0)

友情链接
最近评论
  1. Thiết kế phòng hát karaoke : I got this website from my pal who told me on the topic of this site and now this time I am visiting this site and
    reading very informative articles or reviews here.
  2. Lil Durk : Hello I am so grateful I found your website, I really found you by accident, while
    I was researching on Google for something else, Regardless I am here now and would just like to say
    thanks for a marvelous post and a all round exciting
    blog (I also love the theme/design), I don’t have time to read it all at the moment but I have book-marked it and also
    added your RSS feeds, so when I have time I will be back to read more, Please do keep up the superb b.
  3. Sbobet99 : Howdy thiiѕ is kinda of off tօpic but Ι was wondering if blogs use
    WYSIWYG editors or if you have to manually code with HTML.I'm starting a blog so᧐n butt have no coding skills so I wantеd to get guidаnce
    from someone with experience. Any help would be enormously аpprecіated!
  4. choithethao.tips : Undeniably believe that which you said. Your favorite
    justification seemed to be on the net the easiest thing to be aware of.
    I say to you, I certainly get irked while people consider
    worries that they plainly don't know about. You managed to
    hit the nail upon the top and also defined out the whole thing without having side-effects ,
    people can take a signal. Will likely be back to get more.Thanks
  5. https://veviewwii.tumblr.com/post/662643202115944448/ml-18s21-t2-2 : Link exchange is nothing else however it is simply placing the other
    person's web site link on your page at suitable place and other person will also do similar in support of
    you.
Top