【问题标题】:Why does executing a count() return a PhpMyAdmin error with backtrace为什么执行 count() 会返回带有回溯的 PhpMyAdmin 错误
【发布时间】:2019-05-22 16:48:18
【问题描述】:

我正在尝试通过 PHPMyAdmin 4.8.4 执行以下命令:

SELECT *, count(ref_id) AS c FROM `articles_test` group by ref_id order by c desc

这将返回以下错误消息:

后面跟着这个错误回溯:

./libraries/classes/Display/Results.php#2488 中的注意事项 非对象的属性

回溯

./libraries/classes/Display/Results.php#2389: PhpMyAdmin\Display\Results->_addClass(string 'data hide', boolean 假,NULL,字符串'',) ./libraries/classes/Display/Results.php#3818: PhpMyAdmin\Display\Results->_buildNullDisplay(string '数据隐藏', boolean false, NULL, ) ./libraries/classes/Display/Results.php#3071: PhpMyAdmin\Display\Results->_getDataCellForNonNumericColumns(NULL, 字符串'数据隐藏',NULL,数组,数组,布尔假,数组,数组, 数组,布尔值 false,数组,,NULL,) ./libraries/classes/Display/Results.php#2695: PhpMyAdmin\Display\Results->_getRowValues( , 数组, 整数 24, 数组, 数组,字符串'grid_edit click2',数组,字符串'SELECT *, count(ref_id) AS c FROM articles_test group by ref_id order by c desc', 数组, ) ./libraries/classes/Display/Results.php#4287: PhpMyAdmin\Display\Results->_getTableBody( , 数组, 数组, 数组, boolean false, ) ./libraries/classes/Sql.php#1738: PhpMyAdmin\Display\Results->getTable(, array, array, boolean false, ) ./libraries/classes/Sql.php#2031: PhpMyAdmin\Sql->getHtmlForSqlQueryResultsTable( , 字符串 './themes/pmahomme/img/',NULL,数组,布尔真,字符串'2554', 整数 25, NULL, , 数组, ) ./libraries/classes/Sql.php#2252: PhpMyAdmin\Sql->getQueryResponseForResultsReturned( , 数组, 字符串 'test', 字符串 'articles_test', NULL, NULL, , 字符串 './themes/pmahomme/img/',字符串'2554',整数25,NULL,NULL,NULL, NULL, NULL, string 'SELECT *, count(ref_id) AS c FROM articles_test 按 ref_id 分组,按 c desc', NULL, ) ./import.php#736: PhpMyAdmin\Sql->executeQueryAndGetQueryResponse( 数组,布尔值 false, 字符串'test',字符串'articles_test',NULL,NULL,NULL,NULL,NULL, NULL,字符串'tbl_structure.php',字符串'./themes/pmahomme/img/', NULL, NULL, NULL, 字符串 'SELECT *, count(ref_id) AS c FROM articles_test group by ref_id order by c desc', NULL, NULL, )

我正在运行以下系统:

5.7.24-0ubuntu0.16.04.1 - Apache/2.4.18 (Ubuntu) Datenbank-Client 版本:libmysql - mysqlnd 5.0.12-dev - 20150407 - $Id: b5c5906d452ec590732a93b051f3827e02749b83 $ PHP-Erweiterung: mysqliDokumentation curlDokumentation mbstringDokumentation PHP版本:7.0.32-0ubuntu0.16.04.1

这是一个错误,还是数据库有问题?看不到任何错误,表格看起来还不错。

【问题讨论】:

  • 简单查询有效吗?比如“SELECT * FROMarticles_test LIMIT 1”?
  • 是的,其他一切似乎都有效。我现在升级到最新版本,但仍然是同样的错误。
  • 4.8.4 已经 11 天了。也许它是一个错误?尝试降级到 4.8.3?

标签: mysql phpmyadmin


【解决方案1】:

您使用的 MySQL 版本是什么。查询

SELECT *, count(ref_id) AS c 
FROM `articles_test` 
group by ref_id order by c desc

由于默认的 sql_mode only_full_group_by,将不会在 MySQL 5.7 和更高版本中的默认设置上运行。问题是您将所有列符号 (*) 与聚合函数混合在一起。旧的 MySQL 版本允许这种(错误的)查询,但默认情况下 MySQL 5.7 更严格。

如果您想列出articles_test 中的所有行以及每个ref_id 的计数(对于相同的ref_id 重复相同的值),请使用子查询:

SELECT a.*, count(ref_id) AS c 
FROM articles_test a
  JOIN (
    SELECT at.ref_id, count(*) as refid_count
    FROM articles_test at
    GROUP BY at.ref_id
  ) q as q.ref_id=a.ref_id

【讨论】:

  • 我正在运行以下版本:服务器版本:5.7.24-0ubuntu0.16.04.1 - (Ubuntu)。所以这可能是问题所在。是否有另一种表示法可以返回所有结果和计数器?
猜你喜欢
  • 2021-03-23
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-11-20
  • 2013-02-25
  • 2016-01-08
  • 1970-01-01
相关资源
最近更新 更多