PHP warning in JSON-response 'script=db'
Database management in a single PHP file
Brought to you by:
jakubvrana
When I set
error_reporting(E_ALL);
ini_set("display_errors",1);
then right after selecting a database, I get a javascript exception:
Uncaught SyntaxError: JSON.parse: expected ',' or '}' after property value in object at line 24 column 27 of the JSON data
ajaxSetHtml https://.../?file=functions.js&version=4.8.1:110
onreadystatechange https://.../?file=functions.js&version=4.8.1:108
ajax https://.../?file=functions.js&version=4.8.1:108
ajaxSetHtml https://.../?file=functions.js&version=4.8.1:109
<anonymous> https://.../?username=user&db=mysql:55
It seems that the JSON-response of the following URL is wrong
https://.../?username=user&db=mysql&script=db
raises a waring after each JSON-item.
{
"Comment-columns_priv": "Column privileges",
"Engine-columns_priv": "InnoDB",
"Collation-columns_priv": "utf8_bin",
"Data_length-columns_priv": "16 384",
"Index_length-columns_priv": "0",
"Data_free-columns_priv": "4 194 304",
"Auto_increment-columns_priv": null,
"Rows-columns_priv": "0",
"Comment-component": "Components",
"Engine-component": "InnoDB",
"Collation-component": "utf8_general_ci",
"Data_length-component": "16 384",
"Index_length-component": "0",
"Data_free-component": "4 194 304",
"Auto_increment-component": "1",
"Rows-component": "0",
"Comment-db": "Database privileges",
"Engine-db": "InnoDB",
"Collation-db": "utf8_bin",
"Data_length-db": "16 384",
"Index_length-db": "16 384",
"Data_free-db": "4 194 304",
"Auto_increment-db": null<br />
<b>Warning</b>: Undefined variable $ag in <b>/var/www/html/adminer/adminer.php</b> on line <b>866</b><br />
,
"Rows-db": "~ 2",
"Comment-default_roles": "Default roles",
"Engine-default_roles": "InnoDB",
"Collation-default_roles": "utf8_bin",
"Data_length-default_roles": "16 384",
"Index_length-default_roles": "0",
"Data_free-default_roles": "4 194 304",
"Auto_increment-default_roles": null,
"Rows-default_roles": "0",
"Comment-engine_cost": "",
"Engine-engine_cost": "InnoDB",
"Collation-engine_cost": "utf8_general_ci",
"Data_length-engine_cost": "16 384",
"Index_length-engine_cost": "0",
"Data_free-engine_cost": "4 194 304",
"Auto_increment-engine_cost": null<br />
<b>Warning</b>: Undefined variable $ag in <b>/var/www/html/adminer/adminer.php</b> on line <b>866</b><br />
,
...
As a result, all table information in tables and views is missing. This only happens when PHP warnings are switched on.
The actual issue is that in https://github.com/vrana/adminer/blob/f6880b59d6ab40444407616701c1376c90aba5a5/adminer/script.inc.php#L15 the variable $sql is not initialized. Turning error reporting off is not the right fix of course :-)