折雨的天空

新浪微薄腾讯微薄

最新碎语:最近霉到了住。哎。。。

您的位置:折雨的天空 >php开发> 本地PHP8.1配置wecenter4.1报错:SQLSTATE[42000]: Syntax error or access violation: 1055 Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'peth5.aws_answer.id' which is

本地PHP8.1配置wecenter4.1报错:SQLSTATE[42000]: Syntax error or access violation: 1055 Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'peth5.aws_answer.id' which is

登录以后,点击个人主页报错:


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

这个错误,就是MySQL服务器的配置有关系了,如果按标准的SQL语法,group by时,非聚合函数,都是要出现在group by列的。

找到报错的地方,改一下代码,或者改一下MySQL的配置均可。改MySQL配置的话,就是让MySQL支持非聚合函数列不出现在group by 后面,不推荐这种。


那就改代码吧。


错误SQL:

SELECT * FROM `aws_answer` WHERE `status` = 1 AND `question_id` IN (2,1) GROUP BY `question_id` ORDER BY `is_best` DESC,`agree_count` DESC,`comment_count` DESC

这个查询的列有点多,所以要根据上下文,确定一下到底要查询哪些字段。

报错的文件位置在:

Answer::getHotAnswerByIds([2, 1, 1]) in LogHelper.php line 277
文件位置:

app/common/library/helper/LogHelper.php

if ($last_answers = Answer::getHotAnswerByIds($question_ids))

改为:


if ($last_answers = Answer::getHotAnswerByIds($question_ids,"any_value(id) as id,any_value(content) as content,any_value(against_count) as against_count,any_value(agree_count) as agree_count,any_value(uid) as uid,any_value(comment_count) as comment_count,any_value(uninterested_count) as uninterested_count,any_value(thanks_count) as thanks_count,any_value(answer_user_ip) as answer_user_ip,any_value(answer_user_local) as answer_user_local,any_value(is_anonymous) as is_anonymous,any_value(publish_source) as publish_source,any_value(status) as status,any_value(is_best) as is_best,any_value(best_uid) as best_uid,any_value(best_time) as best_time,any_value(force_fold) as force_fold,any_value(search_text) as search_text,any_value(popular_value) as popular_value,any_value(popular_value_update) as popular_value_update,any_value(create_time) as create_time,any_value(update_time) as update_time,question_id"))


即可。由于这个地方,没有具体分析上下文,原来这里是取的所有字段,所以就把所有字段写出来了,可以详细分析一下上下文,只取需要的字段是最好的。

------------正 文 已 结 束, 感 谢 您 的 阅 读 (折雨的天空)--------------------

转载请注明本文标题和链接:《本地PHP8.1配置wecenter4.1报错:SQLSTATE[42000]: Syntax error or access violation: 1055 Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'peth5.aws_answer.id' which is

奖励一下

取消

分享不易,烦请有多多打赏,如您也困难,点击右边关闭即可!

扫码支持
扫码打赏,5元,10元,你说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

-秒后自动关闭,如已打赏,或者不愿打赏,请点击右上角关闭图标。

发表评论

路人甲 表情
看不清楚?点图切换