596

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?

Machavity
  • 30,841
  • 27
  • 92
  • 100
alebal
  • 5,838
  • 3
  • 10
  • 28
  • 13
    Those who are facing problem as: `if ( count($articles)){..}` in **CodeIgniter**, they should use: `if ( count((array)$articles)){..}` as [here](https://github.com/processwire/processwire-issues/issues/408#issuecomment-337931543) – fWd82 May 31 '18 at 19:32
  • 4
    i had this issue on phpmyadmin v4.6 i updated to 4.8 it disappeared . , looks like it have something to do with mariadb 10.3 as i had not that issue on mariadb 10.1 with phpmyadmin 4.6 – user889030 Jan 25 '19 at 15:17
  • In my case the problem occured when I had installed php 7.3 while my phpMyAdmin was 4.7.1, I switched back to php 7.0 and it works fine or you shoud install version of phpMyAdmin compatible with php 7.3 – vinsa Jun 07 '19 at 22:06

40 Answers40

1150

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

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

On line 613 the count function always evaluates to true since there is no closing parenthesis after $analyzed_sql_results['select_expr']. Making the below replacements resolves this, then you will need to delete the last closing parenthesis on line 614, as it's now an extra parenthesis.

Replace:

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

With:

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

Restart the server apache:

sudo service apache2 restart
Kie
  • 3
  • 2
Jacky Nguyen
  • 11,665
  • 1
  • 7
  • 7
  • 122
    Unbelievable. Works on Ubuntu 18.04 with phpmyadmin installed using apt. – Aloha Jun 08 '18 at 11:22
  • 9
    Worked in that I could select tables, but error returned when I tried to export Db – Alperian Jun 28 '18 at 08:45
  • A bit more info on why this is working would be nice. Is it a bug? Looks like that to me... – Eduard Luca Aug 17 '18 at 20:48
  • 1
    I guess we all make mistakes. This cropped up for me after upgrading PHP from 7.0 -> 7.2, which corresponds to a change made to PHP's count() function: `count() will now yield a warning on invalid countable types passed to the array_or_countable parameter.` – leeman Aug 19 '18 at 16:48
  • 7
    Bug has been reported: https://bugs.launchpad.net/ubuntu/+source/phpmyadmin/+bug/1767361 – Herbert Aug 23 '18 at 08:24
  • 4
    This works for me, thanks! If you get 500 error, check the parentheses before the "count": `(count($analyzed_sql_results['select_expr']) == 1)` – hayatbiralem Sep 25 '18 at 21:57
  • 43
    If you face a similar problem in DB export you need to edit /usr/share/phpmyadmin/libraries/plugin_interface.lib.php, line 551 from _if ($options != null && count($options) > 0) { to _if ($options != null && count((array)$options) > 0) {_ Might be interesting for @alperian and others – Bernd Schuhmacher Nov 06 '18 at 06:39
  • 21
    This didn't work for me. I got `Error in processing request Error code: 500 Error text: Internal Server Error`. The solution of @Chandra Nakka fixed my problem. – Eje Dec 28 '18 at 23:21
  • 2
    Did not require restart, but never hurts. – mckenzm Dec 30 '18 at 08:40
  • Works! Did both edits (in the answer + @Bernd Schuhmacher), now no errors, export is fine. Ubuntu 18.04, php 7.2, MariaDB 10.1.34, phpmyadmin 4.6.6 – Vörös Imi Jan 06 '19 at 16:28
  • 3
    Didn't work for me either. Got the same error as Jee. Chandra Nakka's methods fixed. – Burak Kaymakci Jan 13 '19 at 11:11
  • Not able to find Chandra Nakka's method, @AndréYuhai – sawrubh Jan 21 '19 at 06:48
  • @sawrubh because he changed his name I guess. https://stackoverflow.com/a/50536059/4796762 – Burak Kaymakci Jan 21 '19 at 08:10
  • Thanks, Editing line: Line no 604 for method starting, The line number is 613 and 614 want change – Shanmugavel GK Mar 15 '19 at 19:51
  • 3
    If you are getting a 500 I also had to remove parenthesis after the line OP referenced. `(count($analyzed_sql_results['select_expr']) == 1) && ($analyzed_sql_results['select_expr'][0] == '*'))` – Jeremy Hamm Apr 22 '19 at 01:48
  • 1
    Downvoted because, at today, may of 2019, it causes a server error – realtebo May 02 '19 at 10:48
  • 1
    worked on ubntu 18.04 but why you restart the apache? – peiman F. May 19 '19 at 09:39
  • 1
    @BerndSchuhmacher this information was crucial to me. You should edit this answer to make this information more visible. Thanks a lot for your help ! – AniMir Jul 28 '19 at 11:00
  • 3
    restart not needed – pHoutved Sep 11 '19 at 12:28
  • Works on Ubuntu 18.043 LTS with Package: phpmyadmin Version: 4:4.6.6-5 – Nelu Bidonelu Oct 26 '19 at 15:29
  • If using MAMP on Windows you can find this file in "C:\MAMP\bin\phpMyAdmin\libraries" - restarted and it worked for me as well. – Dean Dec 04 '19 at 03:06
  • Works but keep in mind that the distro version of phpmyadmin for "18.04.3 LTS (Bionic Beaver)" version 4:4.6.6-5 still contains this error. So remove the triple bracket and place it after the square on line 613 – MKZ Dec 28 '19 at 13:34
  • 2
    Works for me Feb 4, 2020 – kr37 Feb 05 '20 at 03:02
  • Had issues with importing database, but @BerndSchuhmacher's comment contained the fix. – David Feb 09 '20 at 02:38
  • Better Upgrade phpMyAdmin to a version, the bug is fixed! see https://stackoverflow.com/a/52019751/1069083 – rubo77 Feb 10 '20 at 23:36
  • I encountered the same error on my Raspberry Pi and this fixed it. Thank you. – dmeehan Mar 31 '20 at 21:59
  • I have faced the same problem at Debian Linux 10 and fixed it with the help of this. Thanks. – Zahid Sumon May 01 '20 at 05:49
  • For me, this is worked: [Nye Liu](https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=890595#15) – Amir Mojiry May 19 '20 at 06:47
  • Also read: https://devnote.in/count-parameter-must-be-an-array-or-an-object/ – Fefar Ravi May 19 '21 at 04:49
  • this answer works but you need to add another parenthesis before the count, here ((count($analyzed_sql_results['select_expr']) == 1) – Alohe Oct 08 '22 at 17:52
692

The Easiest Method:

Just run this below command line in terminal and come back to PhpMyAdmin.

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.

Temüjin
  • 15,371
  • 8
  • 35
  • 57
113

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) && ($analyzed_sql_results['select_expr'][0] == '*')))

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;
 }
Moshe Slavin
  • 5,127
  • 5
  • 23
  • 38
loquace
  • 1,129
  • 1
  • 8
  • 6
  • In the following line you will also have to remove one of the closing paranthesis at the end. – floppes Nov 29 '18 at 08:16
  • Thanks. How did such an error get released with an apt installable package? Just a bit ridiculous. – Josh Morel May 08 '19 at 13:52
  • 1
    @floppes No, it is not correct. You SHOULD NOT remove that closing paranthesis. I have tested your way and it caused `server error`. @loquace's answer should be the one to be accepted. – Long May 10 '19 at 09:11
  • Thanks for spelling it out for us and using bold font where it's needed. Neither the 1st nor the 2nd answers were clear enough for me because they didn't say what they were doing. Editing on nano isn't the same as gedit or whatever. – logicbloke Nov 25 '19 at 08:30
73

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.

shibby
  • 731
  • 4
  • 2
42

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

  • Its worked for me based on condition u have fix internal 500 error was solved, but old error issue "phpmyadmin - count(): Parameter must be an array or an object that implements Countable" is not solved. – shashik493 Oct 05 '18 at 20:23
  • this seems to work for me but does any one know why this has happened? My phpmyadmin was working just fine and then all the sudden I logged in today and it appeared to have this issue? Ubuntu 18.04.2 LTS – probsJustin Apr 16 '19 at 01:24
  • Works on UBuntu 18.04 , wing Nginx , php 7.2 – PHPer Jun 11 '19 at 13:23
37

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) {
jbator
  • 540
  • 4
  • 5
  • This helped me as well, but I had to do both the answer and this. Ubuntu 18.04 – karuhanga Jul 18 '18 at 08:56
  • 2
    This worked to get rid of the error messages, but I think it then avoids the if statement all together and I don't get anything in my database export (with a bunch of errors showing at the bottom after refreshing the page upon completing a database export with a tiny file footprint) – Warren Wang Oct 30 '18 at 23:56
  • 1
    On Debian 9 replace the line 551: ``if ($options != null && count($options) > 0) {`` with : ``if ($options != null) {`` then you can export – BitDEVil2K16 Dec 23 '19 at 13:22
  • This is the fix for the error ending 551 - as error is at line 551. The other fix is good too but is a fix for another problem. This should be the accepted answer for this problem. – alex toader Mar 02 '20 at 15:47
34
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
kaleem
  • 572
  • 6
  • 11
29

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/

Edward Ellsworth
  • 455
  • 5
  • 12
25

Ubuntu 18.04 LTS

These are the steps which worked for me. Many, many thanks to William Desportes for providing the automatic updates on their Ubuntu PPA.

Step 1 (from William Desportes post)
$ sudo add-apt-repository ppa:phpmyadmin/ppa

Step 2
$ sudo apt-get --with-new-pkgs upgrade

Step 3
$ sudo service mysql restart

If you have issues restarting mysql, you can also restart with the following sequence
$ sudo service mysql stop;
$ sudo service mysql start;

Community
  • 1
  • 1
C13L0
  • 611
  • 6
  • 8
24

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

Neoark Software
  • 281
  • 2
  • 5
  • The MySQL and apache reload are not necessary. – Tacsiazuma Nov 04 '18 at 10:49
  • I got this message after file modifications : "— root@Lalla:~# /usr/sbin/pma-secure — Securing phpMyAdmin installation... — ***Setup script won't be able to write configuration.*** — root@Lalla:~# " – cl-r Nov 20 '18 at 00:00
24

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

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

press ctrl+w to search (count($analyzed_sql_results['select_expr'] == 1)

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

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

Restart the server

 sudo service apache2 restart

moreover, If you still facing same issue then do following.

open this file /usr/share/phpmyadmin/libraries/plugin_interface.lib.php

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

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

Ctrl+w : if ($options != null && count($options) > 0) {

replace with following code

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

now save and restart the server

sudo /etc/init.d/apache2 restart
Kundan roy
  • 3,082
  • 3
  • 18
  • 22
  • You simply added a brace. But thanks. I removed the extra brace at the end of the line – redestructa Feb 21 '19 at 14:44
  • I have xampp installed on my mac, I couldnt find /usr/share/phpmyadmin folder and hence '/usr/share/phpmyadmin/libraries/sql.lib.php' this dosent exist for me, can you help in that ? – Saurabh Verma Mar 04 '19 at 11:10
22

I think the best option is to update Phpmyadmin to a version 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.9.4/phpMyAdmin-4.9.4-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.9.4-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.9.4-english phpmyadmin.
  • Now it's time to clean up: rm -rf phpMyAdmin-4.9.4-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.

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.
William Desportes
  • 1,412
  • 1
  • 22
  • 31
PhoneixS
  • 10,574
  • 6
  • 57
  • 73
  • This answer has been incredibly useful! Solved the problem for me! Thanks! PS: You can find blowfish generators online. – lucbas Jan 04 '19 at 13:50
  • 2
    And the solution at this link: https://devanswers.co/manually-upgrade-phpmyadmin/ follows a similar plan, except replaces the blowfish steps with easier ones.. – gwideman Jan 25 '19 at 22:41
  • This is a much better solution compared to editing older versions' config files. – andromeda Apr 25 '19 at 20:32
  • This is the best solution. Following this link: https://devanswers.co/manually-upgrade-phpmyadmin/ I was able to remove the count-parameter error and the Server error 500 error (which is not removed by the accepted answer). Definitely the real problem was the by default installed phpmyadmin version. Thanks a lot. +1. – radiolondra May 10 '21 at 11:43
21

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;
}
Oleksandr P.
  • 370
  • 3
  • 7
  • Thanks! this line is where i was mistaken at the end where i had 3 closing bracket insted i needed 2 closing brackets only && ($analyzed_sql_results['select_expr'][0] == '*')). Worked on phpmyadmin 4.6, php 7.2.10 , ubuntu 18.4.1 – Wang'l Pakhrin Oct 30 '18 at 13:09
  • This worked. There are two changes, on line 613 add missing closing parenthesis for `(count($analyzed_sql_results['select_expr'] == 1)` should be `(count($analyzed_sql_results['select_expr']) == 1)` and remove extra parenthesis on line 614 `&& ($analyzed_sql_results['select_expr'][0] == '*')))` should be `&& ($analyzed_sql_results['select_expr'][0] == '*'))`. – Hmerman6006 Nov 27 '20 at 05:30
15

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;
olealgo
  • 479
  • 11
  • 23
15

Work for me.. Ubuntu 18.04

sudo 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.

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

Just replace with code :

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

Save the file and reload PhpMyAdmin.

Done!!!

TopekoX
  • 319
  • 2
  • 5
12

For my version of phpmyadmin (4.6.6deb5), I found line 613, and realized the count() parentheses were not closed properly. To fix this temporarily until the next release, just change:

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

to:

|| (count($analyzed_sql_results['select_expr']) == 1
J.T.
  • 161
  • 1
  • 4
11

This worked for me;

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

Line No : 614

Replace two codes :

Replace:

(count($analyzed_sql_results[‘select_expr’] == 1)

With:

(count($analyzed_sql_results[‘select_expr’]) == 1)

AND

Replace:

($analyzed_sql_results[‘select_expr’][0] == ‘*’)))

With:

($analyzed_sql_results[‘select_expr’][0] == ‘*’))

save, exit and run

sudo service apache2 restart
ali ozkara
  • 5,425
  • 2
  • 27
  • 24
8

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)

Fabian
  • 650
  • 2
  • 9
  • 21
ibrahim.suez
  • 83
  • 1
  • 1
8

This is fixed in later versions of PHPMyAdmin. The Ubuntu Software Repositories for Ubuntu 18.04.2 holds version 4.6.6.5, while they're currently at 4.9.0.1. Updating your PHPMyAdmin installation will fix this problem, but might prove to be riskier than just editing that one line of code. Here's how I did it on my Ubuntu Server. Steps are essentially the same (with a different path) for all operating systems.

  1. Download PHPMyAdmin.
wget https://files.phpmyadmin.net/phpMyAdmin/4.9.0.1/phpMyAdmin-4.9.0.1-all-languages.zip
unzip phpMyAdmin-4.9.0.1-all-languages.zip
  1. Backup your old PHPMyAdmin installation.
cp -r /usr/share/phpmyadmin ~/phpmyadmin-backup
  1. Drop your new PHPMyAdmin on your old PHPMyAdmin
cd phpMyAdmin-4.9.0.1-all-languages
rm -r /usr/share/phpmyadmin/doc/html
cp -R * /usr/share/phpmyadmin/

Verify that it works. If it doesn't, welll... You have a backup, so restore it and manually edit the faulty line. In my own personal experience, I discovered after doing this that version 4.6.6.5 was not only riddled with bugs, but also incredibly slow compared to the new 4.9.0.1. The speed increase was pure magic for something I though was of "WordPress" quality.

Nato Boram
  • 4,083
  • 6
  • 28
  • 58
7

This worked well for me on Ubuntu 18.04.

Open sql.lib.php file

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

Replace this wrong code:

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

With this one:

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

Save the file.

Restart your server with:

sudo service apache2 restart

And refresh PhpMyAdmin

oklm
  • 135
  • 1
  • 10
6

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

HUGO POLANCO
  • 81
  • 1
  • 2
5

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));"
slfan
  • 8,950
  • 115
  • 65
  • 78
Roland Mester
  • 51
  • 1
  • 2
5

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!

M.A.K. Ripon
  • 2,070
  • 3
  • 29
  • 47
Máté Kiss
  • 105
  • 1
  • 6
5

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

This is what I changed in line 614 and phpmyadmin works without any error. Need one ( before count, and one ) before == . That's it.

Bikram Nath
  • 483
  • 6
  • 15
5

Just correct the count() function and closing parentheses from line 604 till 615 in /usr/share/phpmyadmin/libraries/sql.lib.php file:

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;
}
EricSchaefer
  • 25,272
  • 21
  • 67
  • 103
mollas85
  • 81
  • 1
  • 2
4

I tried all of above solution but didn't work for me.

Try this:-

Install required version of PHP(in my case 7.0) and then in terminal, type

sudo update-alternatives --config php

Output will be like this :-

enter image description here

Then you can switch to any version of PHP by simply entering the selection number(in my case 1).

Hope this may help other -:)

Tridev Shrestha
  • 447
  • 7
  • 21
3

Open the /usr/share/phpmyadmin/sql.lib.php file with elevated privileges, and edit the following in the function PMA_isRememberSortingOrder():

  1. ~ line 613 to fix the initial error:
    • Replace || count($analyzed_sql_results['select_expr'] == 1)
    • With || (count($analyzed_sql_results['select_expr']) == 1)
  2. ~ line 614 to fix the 500 error that will probably follow:
    • Replace && ($analyzed_sql_results['select_expr'][0] == '*')))
    • With && ($analyzed_sql_results['select_expr'][0] == '*'))

Restart your Apache server: sudo service apache2 restart.

Tested on Linux Mint 19.1 based on Ubuntu 18.04, with PhpMyAdmin 4.6.6 and PHP 7.2.

elenche
  • 171
  • 2
  • 7
3

Replace 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;
}
Alejandro Reyes
  • 332
  • 5
  • 13
3

Add the phpmyadmin ppa

sudo add-apt-repository ppa:phpmyadmin/ppa
sudo apt-get update
sudo apt-get upgrade
HosseyNJF
  • 491
  • 1
  • 6
  • 18
faye.babacar78
  • 774
  • 7
  • 12
3
add-apt-repository ppa:phpmyadmin/ppa
apt-get clean
apt-get update
apt-get purge phpmyadmin
apt-get install phpmyadmin

Fixed it for me, on Ubuntu 18.04.

Eliezer Berlin
  • 3,170
  • 1
  • 14
  • 27
2

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

See an 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.

sandip
  • 533
  • 9
  • 29
amrit
  • 36
  • 4
2

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

Stephen Rauch
  • 47,830
  • 31
  • 106
  • 135
KingNonso
  • 712
  • 7
  • 7
2

I see that you are all editing or updating from our files

For those who want automatic updates you can use our Ubuntu PPA

sudo add-apt-repository ppa:phpmyadmin/ppa

And for Debian users you will need to wait for next version of Debian or use PPA

Ubuntu 20 has phpMyAdmin 4.9 or a later version

Debian issue on our tracker

Countable issues on our tracker

TLDR Update to latest 4.9 or 5.0 version to solve this issue.

William Desportes
  • 1,412
  • 1
  • 22
  • 31
1

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"
cwhisperer
  • 1,478
  • 1
  • 32
  • 63
1

As the error in code in conf file may vary (@Jacky Nguyen vs @ĦΔŇĐŘΔ ŇΔҜҜΔ answers),
the general solution answer would be to
a) correct the condition logic in conf file to make sense
(x)or b) install corrected/current phpmyadmin

As for a)

  1. open the file with error code
    For the terminal people: sudo nano /usr/share/phpmyadmin/libraries/sql.lib.php
    For the regular folks: sudo gedit /usr/share/phpmyadmin/libraries/sql.lib.php

  2. find the condition - basically search for $analyzed_sql_results['select_expr']

  3. now the logic should be to check whether this sub array is empty, or, whether it has just 1 element with a value "*

  4. so basically the block
    between && $analyzed_sql_results['select_from']
    and && count($analyzed_sql_results['select_tables']) == 1
    should look something like this

&& (
    empty($analyzed_sql_results['select_expr']) //the sub array is empty,
    || //or,
    (
        (count($analyzed_sql_results['select_expr']) == 1) //it has just 1 element
        && //and at the same time
        ($analyzed_sql_results['select_expr'][0] == '*') //the 1 element value is "*"
    )
)

This is a good example of why to indent and beautify your code, if it would be indeted correctly, I believe this would never happen, or at least, would be more easily found.

Community
  • 1
  • 1
jave.web
  • 13,880
  • 12
  • 91
  • 125
  • I have xampp installed on my mac, I couldnt find /usr/share/phpmyadmin folder and hence '/usr/share/phpmyadmin/libraries/sql.lib.php' this dosent exist for me, can you help in that ? – Saurabh Verma Mar 04 '19 at 11:11
  • @SaurabhVerma perform a file search for sql.lib.php or for the phpmyadmin folder - if you have phpmyadmin, it must be installed somewhere – jave.web Mar 04 '19 at 17:40
1

is_countable function introduced in (PHP 7 >= 7.3.0)

is_countable — Verify that the contents of a variable is a countable value.

use this function following way ::

is_countable ( $var )

It will return boolean value. For more detail please visit on http://php.net/manual/en/function.is-countable.php

Vipul
  • 896
  • 7
  • 14
1

Based on @jbator's answer, you can edit /usr/share/phpmyadmin/libraries/plugin_interface.lib.php and replace this line:

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

with these lines:

if ($options != null &&
   ((is_array($options) || $options instanceof Countable) && count($options) > 0) ||
   (method_exists($options, 'getProperties') && $options->getProperties() != null && (is_array($options->getProperties()) || $options->getProperties() instanceof Countable) && count($options->getProperties()) > 0)) {

In this way, we won't have empty exported file.

Farahmand
  • 2,731
  • 1
  • 24
  • 27
1

Take a look: https://devanswers.co/problem-php-7-2-phpmyadmin-warning-in-librariessql-count/

Firstly, backup sql.lib.php before editing. Edit sql.lib.php in nano.

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

Press CTRL + W and search for (count($analyzed_sql_results['select_expr'] == 1)

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

Save file and exit. (Press CTRL + X, press Y and then press ENTER)

M E S A B O
  • 783
  • 1
  • 11
  • 15
1

Here's an automated patching script I threw together utilizing Chandra Nakka's answer.

FILE="/usr/share/phpmyadmin/libraries/sql.lib.php"
PATTERN="(count(\$analyzed_sql_results\['select_expr'\] == 1)"

echo "Verifying broken code in $FILE"

if grep -q "$PATTERN" "$FILE"; then
  LINE_NUMBER=$(grep -n "$PATTERN" "$FILE" | cut -d : -f 1)
  echo "Broken code found on line: $LINE_NUMBER"
  BEFORE_CODE=$(sed -n "$LINE_NUMBER"p "$FILE")

  echo -e "\nCreating backup of $FILE"
  sudo cp "$FILE" "$FILE-backup-$(date +"%Y-%m-%dT%H%M%S")"
  echo "Backup created at: $FILE-backup-$(date +"%Y-%m-%dT%H%M%S")"

  echo -e "\nApplying fix"
  sudo sed -i "s/|\s*\((count(\$analyzed_sql_results\['select_expr'\]\)/| (\1)/g" $FILE
  AFTER_CODE=$(sed -n "$LINE_NUMBER"p "$FILE")

  # Trim before and after code with xargs
  echo "BEFORE: $(echo $BEFORE_CODE | xargs)"
  echo " AFTER: $(echo $AFTER_CODE | xargs)"
else
  echo "Broken code not found. Maybe it's already been patched "
fi
CTS_AE
  • 12,987
  • 8
  • 62
  • 63
0

none of these solutions worked for me you need to update phpmyadmin to the latest, follow instructions here

https://askubuntu.com/questions/947805/how-to-upgrade-phpmyadmin-revisited

Benjamin Gakami
  • 1,610
  • 2
  • 16
  • 22