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 · 6 comments

Comments

Projects
None yet
5 participants
@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

This comment has been minimized.

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

This comment has been minimized.

Copy link

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

This comment has been minimized.

Copy link
Member

williamdes commented Jun 10, 2018

@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

This comment has been minimized.

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

This comment has been minimized.

Copy link
Member

ibennetch commented Aug 17, 2018

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.

@ibennetch ibennetch added the duplicate label Aug 17, 2018

@ibennetch ibennetch closed this Aug 17, 2018

@ZhengDengJue

This comment has been minimized.

Copy link

ZhengDengJue commented Nov 12, 2018

I solved the issu! thanks so much!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment