Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

count(): Parameter must be an array or an object that implements Countable #14332

Closed
alimp5 opened this issue May 27, 2018 · 8 comments
Closed

Comments

@alimp5
Copy link

alimp5 commented May 27, 2018

Expected behaviour

as default, phpmyadmin tries to load COUNT SQL function for counting the number of stored records in DB and then fetch to show them on browser.

Apache Log

[Sun May 27 13:31:22.267263 2018] [php7:emerg] [pid 804] [client 192.168.100.10:35042] PHP Parse error:  syntax error, unexpected ''' (T_CONSTANT_ENCAPSED_STRING) in /usr/share/phpmyadmin/libraries/sql.lib.php on line 614

cat sql.lib.php (as default):

function PMA_isRememberSortingOrder($analyzed_sql_results)
{
    return $GLOBALS['cfg']['RememberSorting']
        && ! ($analyzed_sql_results['is_count']
            || $analyzed_sql_results['is_export']
            || $analyzed_sql_results['is_func']
            || $analyzed_sql_results['is_analyse'])
        && $analyzed_sql_results['select_from']
        && ((empty($analyzed_sql_results['select_expr']))
            || (count($analyzed_sql_results['select_expr'] == 1)
                && ($analyzed_sql_results['select_expr'][0] == '*')))
        && count($analyzed_sql_results['select_tables']) == 1;
}

Solution

cat sql.lib.php (edited):

function PMA_isRememberSortingOrder($analyzed_sql_results)
{
    return $GLOBALS['cfg']['RememberSorting']
        && ! ($analyzed_sql_results['is_count']
            || $analyzed_sql_results['is_export']
            || $analyzed_sql_results['is_func']
            || $analyzed_sql_results['is_analyse'])
        && $analyzed_sql_results['select_from']
        && ((empty($analyzed_sql_results['select_expr']))
            || (count($analyzed_sql_results['select_expr']) == 1
                && ($analyzed_sql_results['select_expr'][0] == '*')))
        && count($analyzed_sql_results['select_tables']) == 1;
}

Actual behaviour

I saw below error:

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 'dbdbdb',
string 'ap_dbdb',
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
string '',
string './themes/pmahomme/img/',
NULL,
NULL,
NULL,
string 'SELECT * FROM `ap_dbdb`',
NULL,
NULL,
)
./sql.php#221: PMA_executeQueryAndSendQueryResponse(
array,
boolean true,
string 'dbdbdb',
...
...
...
...

Server configuration

Operating system:
Kali Linux _ 2018.3 _ RasberryPi Zero

Web server:
Apache2 _ 2.4.29-2

Database:
MariaDB 1.10-29

PHP version:
PHP 7.2.4-1 (cli) (built: Apr 5 2018 08:50:27) ( NTS )

phpMyAdmin version:
4.6.6deb5

Client configuration

Browser:
Firefox _ Latest version

@williamdes
Copy link
Member

williamdes commented Jun 10, 2018

Same issue with 4.5.1 :
Warning in ./libraries/sql.lib.php#570 count(): Parameter must be an array or an object that implements Countable

@alimp5 Can you try with version 4.8.1 ?

Actual file

private function isRememberSortingOrder(array $analyzed_sql_results)
{
return $GLOBALS['cfg']['RememberSorting']
&& ! ($analyzed_sql_results['is_count']
|| $analyzed_sql_results['is_export']
|| $analyzed_sql_results['is_func']
|| $analyzed_sql_results['is_analyse'])
&& $analyzed_sql_results['select_from']
&& isset($analyzed_sql_results['select_expr'])
&& isset($analyzed_sql_results['select_tables'])
&& ((empty($analyzed_sql_results['select_expr']))
|| ((count($analyzed_sql_results['select_expr']) == 1)
&& ($analyzed_sql_results['select_expr'][0] == '*')))
&& count($analyzed_sql_results['select_tables']) == 1;
}

@alimp5
Copy link
Author

alimp5 commented Jun 10, 2018

@williamdes

Use and check below one (edited and fixed):
I hope thia edited code help you.

 	     private function isRememberSortingOrder(array $analyzed_sql_results) 
	     { 
	         return $GLOBALS['cfg']['RememberSorting'] 
	             && ! ($analyzed_sql_results['is_count'] 
	                 || $analyzed_sql_results['is_export'] 
	                 || $analyzed_sql_results['is_func'] 
	                 || $analyzed_sql_results['is_analyse']) 
	             && $analyzed_sql_results['select_from'] 
	             && isset($analyzed_sql_results['select_expr']) 
	             && isset($analyzed_sql_results['select_tables']) 
	             && ((empty($analyzed_sql_results['select_expr'])) 
	                 || (count($analyzed_sql_results['select_expr']) == 1
	                     && ($analyzed_sql_results['select_expr'][0] == '*'))) 
	             && count($analyzed_sql_results['select_tables']) == 1; 
	     } 

@williamdes
Copy link
Member

@alimp5 I do not understand what is the issue with this code sample.

use ```php codehere ``` for php code 😉

Can you edit the unit test to add what you think is the issue ?

public function testIsRememberSortingOrder()
{
// Test environment.
$GLOBALS['cfg']['RememberSorting'] = true;
$this->assertTrue(
$this->callProtectedMethod('isRememberSortingOrder', [
$this->sql->parseAndAnalyze('SELECT * FROM tbl')
])
);
$this->assertFalse(
$this->callProtectedMethod('isRememberSortingOrder', [
$this->sql->parseAndAnalyze('SELECT col FROM tbl')
])
);
$this->assertFalse(
$this->callProtectedMethod('isRememberSortingOrder', [
$this->sql->parseAndAnalyze('SELECT 1')
])
);
$this->assertFalse(
$this->callProtectedMethod('isRememberSortingOrder', [
$this->sql->parseAndAnalyze('SELECT col1, col2 FROM tbl')
])
);
$this->assertFalse(
$this->callProtectedMethod('isRememberSortingOrder', [
$this->sql->parseAndAnalyze('SELECT COUNT(*) from tbl')
])
);
}

rcount ?
RE-edit :

 private function isRememberSortingOrder(array $analyzed_sql_results) 
	     { 
	         return $GLOBALS['cfg']['RememberSorting'] 
	             && ! ($analyzed_sql_results['is_count'] 
	                 || $analyzed_sql_results['is_export'] 
	                 || $analyzed_sql_results['is_func'] 
	                 || $analyzed_sql_results['is_analyse']) 
	             && $analyzed_sql_results['select_from'] 
	             && isset($analyzed_sql_results['select_expr']) 
	             && isset($analyzed_sql_results['select_tables']) 
	             && ((empty($analyzed_sql_results['select_expr'])) 
	                 || (count($analyzed_sql_results['select_expr']) == 1)
	                     && ($analyzed_sql_results['select_expr'][0] == '*')) 
	             && count($analyzed_sql_results['select_tables']) == 1; 
	     } 

@tiny6996
Copy link

tiny6996 commented Jul 6, 2018

I was having the same issue on ubuntu 18.04 with php 7.2 and maria db 10.1 however based on this stack exchange thread all that needed to be changed the code listed below sql.lib.php file

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

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

@ibennetch
Copy link
Member

I think this is a duplicate of #13938, which relates to using an older phpMyAdmin version with PHP 7.2.

The problem was fixed with version 4.7.8; I recommend though that you upgrade to the newest phpMyAdmin which is currently version 4.8.2.

@ZhengDengJue
Copy link

I solved the issu! thanks so much!

@GrigoriyMo
Copy link

I was having the same issue on ubuntu 18.04 with php 7.2 and maria db 10.1 however based on this stack exchange thread all that needed to be changed the code listed below sql.lib.php file

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

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

Thank You!

@smellyonionman
Copy link

smellyonionman commented Mar 5, 2019

Edit: Sorry. I see why this was closed now. We should be pestering someone else about Apt installing older versions of PhpMyAdmin as it seems we are out of date @GrigoriyMo - but in case it helps anyone I'll leave this comment.

I also had the issue mentioned above, but had to make a different edit. For me, line 613 should read:
|| ((count($analyzed_sql_results['select_expr']) == 1)

It looks like there have been some new lines added to this function since the StackExchange question was first answered, so this "patch" has been updated.

Berd Schumacher was also helpful in showing how to fix Export functions, also broken:
Line 551 of plugin_interface.lib.php should read:
if ($options != null && count((array)$options) > 0) {

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jun 21, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

7 participants