phpmyadmin - count(): Parameter must be an array o

2019-01-16 00:44发布

问题:

I've uploaded the backup to a table, opening the table I see this:

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

Backtrace

./libraries/sql.lib.php#2038: PMA_isRememberSortingOrder(array)
./libraries/sql.lib.php#1984: PMA_executeQueryAndGetQueryResponse(
array,
boolean true,
string 'alternativegirls',
string 'tgp_photo',
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
string '',
string './themes/pmahomme/img/',
NULL,
NULL,
NULL,
string 'SELECT * FROM `tgp_photo`',
NULL,
NULL,
)
./sql.php#216: PMA_executeQueryAndSendQueryResponse(
array,
boolean true,
string 'alternativegirls',
string 'tgp_photo',
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
string '',
string './themes/pmahomme/img/',
NULL,
NULL,
NULL,
string 'SELECT * FROM `tgp_photo`',
NULL,
NULL,
)
./index.php#53: include(./sql.php)

Inside phpMyAdmin...

PHP is 7.2, the server is Ubuntu 16.04, installed yesterday.

Looking for I saw that some have this error in their code, but I did not find anyone who received it in phpMyAdmin...

What should I do? Is that my error? A phpmyadmin error? wait update ? I go back to PHP 7.1?

回答1:

Edit file /usr/share/phpmyadmin/libraries/sql.lib.php:

sudo nano /usr/share/phpmyadmin/libraries/sql.lib.php

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

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

Restart the server

sudo service apache2 restart


回答2:

Easiest Method:

Just run this below command line in terminal and come back to PhpMyAdmin. Now it works fine :)

sudo sed -i "s/|\s*\((count(\$analyzed_sql_results\['select_expr'\]\)/| (\1)/g" /usr/share/phpmyadmin/libraries/sql.lib.php

Manual Method:

Open sql.lib.php file

nano /usr/share/phpmyadmin/libraries/sql.lib.php

Find for count($analyzed_sql_results['select_expr'] code on file. You can get this at line ~613. You can see this below wrong code

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

Just replace that wrong code with this below one

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

Save the file and come to PhpMyAdmin.

Now it works fine :)



回答3:

tested on Debian, should works on Ubuntu:

1.) First download latest phpMyadmin file.

2.) Delete (make a backup) all previous version file located in /usr/share/phpmyadmin directory.

3.) Uncompress to /usr/share/phpmyadmin/ directory all files of latest phpmyadmin.

4.) Modify file libraries/vendor_config.php and change line:

define('CONFIG_DIR', '');

to

define('CONFIG_DIR', '/etc/phpmyadmin/');

and

define('TEMP_DIR', './tmp/');

to

define('TEMP_DIR', '/tmp/');

5.) restart apache server and done.



回答4:

I found this PHP 7.2 count() - SYNTAX error in sql.lib.php

That perfectly works on my config:

Debian 9, 
PHP 7.2.3-1+0~20180306120016.19+stretch~1.gbp81bf3b (cli) (built: Mar  6 2018 12:00:19) ( NTS )

Open /usr/share/phpmyadmin/libraries/sql.lib.php

Change line: Move parenthesis before ==

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

in

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;
 }


回答5:

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

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

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

this worked for me



回答6:

Works on UBUNTU 18.04 


Edit file: '/usr/share/phpmyadmin/libraries/sql.lib.php'
Replace: (count($analyzed_sql_results['select_expr'] == 1)
With:  ((count($analyzed_sql_results['select_expr']) == 1)

Restart the server
sudo service apache2 restart


回答7:

phpmyadmin 4.7.4 is supposed to have "Fixed several compatibility issues with PHP 7.2"

Chances are you have an older version of phpmyadmin.

https://www.phpmyadmin.net/news/2017/8/24/phpmyadmin-474-released/



回答8:

If someone have similar error in DB export page (I had this issue in Ubuntu 18.04), then replace line 551 in file /usr/share/phpmyadmin/libraries/plugin_interface.lib.php with code

if ($options != null && (is_array($options) || $options instanceof Countable) && count($options) > 0) {


回答9:

Proceed following steps at ubuntu-18.04:

Step 1) locate sql.lib.php

It will show something like:

/usr/share/phpmyadmin/libraries/sql.lib.php

Step 2) Open terminal (Alt t) and write:

sudo /usr/sbin/pma-configure

Step 3)sudo gedit /usr/share/phpmyadmin/libraries/sql.lib.php and search below function:

 

    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;
     }

Step 4) Replace above function with:


     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;
     }

Step 4) Save & close file and below command on terminal

sudo /usr/sbin/pma-secure

Step 5) sudo service mysql reload

Step 6) sudo service apache2 reload

It works for me.. Goodluck



回答10:

Try replace this function in file: /usr/share/phpmyadmin/libraries/sql.lib.php

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;
}


回答11:

Warning in ./libraries/plugin_interface.lib.php#532

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

couse of phpmyadmin’s library try to count some parameter. At this line 532, I found this code in this path.

Edit File /usr/share/phpmyadmin/libraries/plugin_interface.lib.php at line 532:

sudo nano /usr/share/phpmyadmin/libraries/plugin_interface.lib.php

Find the line if ($options != null && count($options) > 0) { and replace count($options) with count((array)$options).

Restart Apache Service:

sudo service apache2 restart

In new php version it can’t use count() or sizeof() with un array type. So you have to forcefully change the parameter to array here.



回答12:

Works on UBUNTU 16.04.3 Just open

usr/share/libraries/sql.lib.php

modify

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

To

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



回答13:

I think the best option is to update Phpmyadmin to a versión which has this already fixed.

Until it is published as a deb, you could do it like in @crimson-501 answer which I will copy below:

  • Your first step is to install PMA (phpMyAdmin) from the official Ubuntu repo: apt-get install phpmyadmin.
  • Next, cd into usr/share directory: cd /usr/share.
  • Third, remove the phpmyadmin directory: rm -rf phpmyadmin.
  • Now we need to download the latest PMA version onto our system (Note that you need wget: apt-get install wget): wget -P /usr/share/ "https://files.phpmyadmin.net/phpMyAdmin/4.8.2/phpMyAdmin-4.8.2-english.zip" Let me explain the arguments of this command, -P defines the path and "the link.zip" is currently (7/17/18) the latest version of PMA. You can find those links HERE.
  • For this next step you need unzip (apt-get install unzip): unzip phpMyAdmin-4.8.2-english.zip. We just unzipped PMA, now we will move it to it's final home.
  • Lets use the cp (copy) command to move our files! Note that we have to add the -r argument since this is a folder. cp -r phpMyAdmin-4.8.2-english phpmyadmin.
  • Now it's time to clean up: rm -rf phpMyAdmin-4.8.2-english.

Keep Reading!

You might now notice two errors after you log into PMA.

the configuration file now needs a secret passphrase (blowfish_secret). phpmyadmin
The $cfg['TempDir'] (./tmp/) is not accessible. phpMyAdmin is not able to cache templates and will be slow because of this.

However, these issues are relatively easy to fix. For the first issue all you have to do is grab your editor of choice and edit /usr/share/phpmyadmin/config.inc.php but there's a problem, we removed it! That's ok, all you have to do is: cd /usr/share/phpmyadmin & cp config.sample.inc.php config.inc.php.

  • We will now add our Blowfish Secret! nano config.inc.php and copy the dynamically generated secret from near the bottom of this page: https://www.question-defense.com/tools/phpmyadmin-blowfish-secret-generator.

Example phpMyAdmin Blowfish Secret Variable Entry:

/*
 * This is needed for cookie based authentication to encrypt password in
 * cookie
 */
$cfg['blowfish_secret'] = '{^QP+-(3mlHy+Gd~FE3mN{gIATs^1lX+T=KVYv{ubK*U0V'; 
/* YOU MUST FILL IN THIS FOR COOKIE AUTH! */

Now save and close the file.

  • Now we will create a tmp directory for PMA: mkdir tmp & chown -R www-data:www-data /usr/share/phpmyadmin/tmp. The last command allows the Apache web server to own the tmp directory and edit it's contents.


回答14:

Ubuntu 18.10 (December, 2018)

Line 613, 614, 615, replace with:

        || count($analyzed_sql_results['select_expr']) == 1
            && ($analyzed_sql_results['select_expr'][0] == '*'))
    && count($analyzed_sql_results['select_tables']) == 1;


回答15:

Edit file '/usr/share/phpmyadmin/libraries/sql.lib.php' Replace: (make backup)

"|| (count($analyzed_sql_results['select_expr'] == 1) 
&&($analyzed_sql_results['select_expr'][0] == '*'))) 
&& count($analyzed_sql_results['select_tables']) == 1;"

With:

"|| (count($analyzed_sql_results['select_expr']) == 1) 
&& ($analyzed_sql_results['select_expr'][0] == '*') 
&& (count($analyzed_sql_results['select_tables']) == 1));"


回答16:

I had this issue when using windows and the responses above solved it for me, however when i switched to linux (ubuntu 18.04 LTS) I had the same issue and couldn't figure out how to solve it because I didn't see the file '/usr/share/phpmyadmin/libraries/sql.lib.php'.

This sql.lib.php file wasn't in the share folder or the phpmyadmin/libraries folder of my /opt/lampp directory - since I was using xampp on my ubuntu. Based on the update made to the xampp (because I used the latest installation as of now) setup.

The answer is still to replace: (count($analyzed_sql_results['select_expr'] == 1)

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

However the file to look for is Sql.php found in /opt/lampp/phpmyadmin/libraries/classes/Sql.php

Future updates or if you still don't find it: use grep -r 'count($analyzed_sql_results' /opt/lampp/phpmyadmin to search for matching documents in your directory and edit accordingly



回答17:

Upgrade to phpMyAdmin 4.8.3. this solves the PHP 7.2 compatibility issues



回答18:

On Ubuntu 18.04 with MariaDb and Nginx, I solved it with updating file /usr/share/phpmyadmin/libraries/sql.lib.php as follows:

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

The answer mentioned by @Nguyen throws a 500 error saying:

FastCGI sent in stderr: "PHP message: PHP Parse error:  syntax error, unexpected ')', expecting ';' in /usr/share/phpmyadmin/libraries/sql.lib.php on line 614"


回答19:

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

see error on your error

./libraries/sql.lib.php#2038: PMA_isRememberSortingOrder(array) ./libraries/sql.lib.php#1984: PMA_executeQueryAndGetQueryResponse(

go to this line and remove the function call.

It works for me. Thank you



回答20:

There is no need to use count if it is has single value or not because this is issue in first place. You can read more about it here http://php.net/manual/en/function.count.php

Now count will not work on NULL, Boolean, String, Integer. This is the reason here and you have to only replace the count with empty.

Check out what I did

&& ((empty($analyzed_sql_results['select_expr']))
        || (!empty($analyzed_sql_results['select_expr'])
            && ($analyzed_sql_results['select_expr'][0] == '*')))


回答21:

Hi the following solve my same problem absolutely (import/export and so on):

Fix Bug Phpmyadmin [plugin_interface.lib.php] + Php7.2 + Ubuntu 16.04

so... under ubuntu 18.04, mysql, php7.2: Terminal:

sudo gedit /usr/share/phpmyadmin/libraries/plugin_interface.lib.php

Find the following line(ctrl+f):

if ($options != null && count($options) > 0) {

it was on line #551 for me

and change for following:

if ($options != null && count((array)$options) > 0) {

ctrl+s for save the changes

and in terminal: ctrl+c for get back promt...

and: sudo systemctl restart apache2

"I think in new php version.It can’t use count() or sizeof() with un array type. Force parameter to array is easy way to solve this bug,..."

Thanks for the original author for the problem solving! I try to share it!



回答22:

In my case (Ubuntu 18.04), the solutions above did not work. I did not understand why. Then I noticed I also had several other warning messages. After some investigation, I found out my PHP version (7.2) was not compatible with my PHPMyAdmin version. So all what I did was to upgrade the later one (version 4.8.4).



回答23:

put @count() where it giving the error it will Hide the error ..

(@count($analyzed_sql_results['select_expr'] == 1)
            && ($analyzed_sql_results['select_expr'][0] == '*')))
    && (@count($analyzed_sql_results['select_tables']) == 1);

Hope this will Fix the problem