Control select not display the value in Adminer Editor
Database management in a single PHP file
Brought to you by:
jakubvrana
I am using Adminer Editor 4.8.1. With PHP 8.0.10 (on Apache 2.4.) it works without errors. I have upgraded to PHP 8.1.10 and this problems appears:
Listing of table rows displays correctly value in column with foreign key into referenced table, but if one row is displayed (.../editor/?username=user&edit=article&where%5Bid%5D=1) the select control has no selected value.
I have tested also the Editor 4.7.9 on PHP 8.1.10 - the same error.
After downgrading back to PHP 8.0.10 Editor works correctly.
Iam using mySQL mysqlnd 8.1.10
Hi,
I have succeeded to fix the error, the error was probably caused a difference type of database column integer selecting into PHP (PDO??). In function generating the SELECT html, file /adminer/include/function.inc.php, line 194 is function optionList getting in argument $selected the value of the int column in database table (foreign key). I have tested - PHP 8.0.10 it is number but type string, but in PHP 8.1.10 it is nubmer but type integer !!! And on line 203, where is creating the html attribute selected for <option> which represents the value is comparison type strict === and for $use_keys = true (for Editor) the $key is retyping to (string) but the value in $selected NOT !! So I have made a slight change of the code - adding retyping to (string) lselected.</option>
And this works in PHP 8.1.10 !!
I havent tested wheather it works also in PHP 8.0.10 but probably yes.
If
$key
is an empty string and$selected
is null then your code will match them which is wrong.Hi Jakub, it's nice to hear from you.
My fix is just emergency fix, because I urgently need use Editor on home development machine with Windows. I do not fully undersand the source code of Adminer/Editor. The root of the bug will be probably in library PDO in version >= PHP 8.1 for Windows, I didnt found the root of the bug. My fix isnt correct solution of the problem, I know.
What you can do is compare Adminer/Editor on PHP 8.1 on Linux and Windows and found the place in the PDO where is difference and fix the PDO bug directly there
I've merged your change. Hopefully it wouldn't break anything else.