in How To

How to: phpMyAdmin Warning in ./libraries/sql.lib.php#601

Mi è capitato di utilizzare phpMyAdmin versione 4.5.4.1 installato su un server Ubuntu 16.04.3 LTS e di trovare questo errore quando cerco di vedere i record contenuti in un tabella.

L’errore che si presentava era

Some error have been detected on the server. 
Please look at the bottom of this window.

Questo il messaggio riportato nella pagina di phpMyAdmin.

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

Cercando in rete il problema ho trovato che questo era dovuto ad un bug nel codice sorgente di phpMyAdmin.

Il problema è legato ad un errori di sintassi nel codice sorgente PHP.

Questo il codice sorgente originale

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

Il problema è evidenziato in queste righe

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

in cui il codice presenta delle parentesi chiuse in modo errato.

Nella riga

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

la funzione count non ha la parentesi di chiusura e nella successiva riga

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

è presenta una parentesi di troppo a chiusura dell’istruzione.

Se si decide di correggere manualmente il problema senza ricorrere ad aggiornamenti di phpMyAdmin questa è la versione corretta del codice.

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

Scrivi un commento

Commento