SQL 参数必须是在phpmyadmin中实现Countable的数组或对象

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/51109440/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 23:21:27  来源:igfitidea点击:

Parameter must be an array or an object that implements Countable in phpmyadmin

sqlwordpress

提问by Lee

When I try and view the wp_posts table in phpmyadmin, I see this error message, but have no idea what it means and have never seen it before.

当我尝试在 phpmyadmin 中查看 wp_posts 表时,我看到此错误消息,但不知道它的含义并且以前从未见过。

Can someone help me try and get rid of this somehow?

有人可以帮我尝试以某种方式摆脱它吗?

Warning in ./libraries/sql.lib.php#613
count(): Parameter must be an array or an object that implements Countable

Backtrace

./libraries/sql.lib.php#2128: PMA_isRememberSortingOrder(array)
./libraries/sql.lib.php#2079: PMA_executeQueryAndGetQueryResponse(
array,
boolean true,
string 'afterhours',
string 'wp_posts',
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
string '',
string './themes/original/img/',
NULL,
NULL,
NULL,
string 'SELECT * FROM `wp_posts`',
NULL,
NULL,
)
./sql.php#221: PMA_executeQueryAndSendQueryResponse(
array,
boolean true,
string 'afterhours',
string 'wp_posts',
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
string '',
string './themes/original/img/',
NULL,
NULL,
NULL,
string 'SELECT * FROM `wp_posts`',
NULL,
NULL,
)

回答by A. MacGillivray

This appears to be a duplicate of phpmyadmin - count(): Parameter must be an array or an object that implements Countable

这似乎是phpmyadmin的副本- count(): Parameter must be an array or an object that implementation Countable

According to the top answer on the linked post, it looks like there may be an error in the ./libraries/sql.lib.php that is causing the code to attempt a count() function on something other than an array (or an object that implements "Countable"). To fix it (according to the linked response):

根据链接帖子上的最佳答案,看起来 ./libraries/sql.lib.php 中可能存在错误,导致代码尝试对数组(或实现“Countable”的对象)。要修复它(根据链接的响应):

Edit file '/usr/share/phpmyadmin/libraries/sql.lib.php' and replace

编辑文件 '/usr/share/phpmyadmin/libraries/sql.lib.php' 并替换

(count($analyzed_sql_results['select_expr'] == 1) 

With:

和:

(count($analyzed_sql_results['select_expr']) == 1

This works because:

这是有效的,因为:

  • count cannot be performed on a non-array (hence your error, "Parameter must be an array or an object that implements Countable")
  • "== 1" in count() is an equivalency test, not an array
  • removing "== 1" from count() leaves a count(array) function, which works.
  • count 不能在非数组上执行(因此你的错误,“参数必须是一个数组或一个实现 Countable 的对象”)
  • count() 中的“== 1”是等价测试,而不是数组
  • 从 count() 中删除“== 1”会留下一个 count( array) 函数,该函数有效。

回答by Oscar Otero

I solved the problem by validating if it really is an array using the is_array() function like this:

我通过使用 is_array() 函数验证它是否真的是一个数组来解决这个问题,如下所示:

if (is_array($yourArray)) {
    //Your count()
}

回答by anmari

Consider updating phpmyadmin and fix a whole bunch of bugs. It's now on 4.8.2 https://www.phpmyadmin.net/news/

考虑更新 phpmyadmin 并修复一大堆错误。现在是 4.8.2 https://www.phpmyadmin.net/news/