Line 952 (2.11.9) or line 906 (trunk) of relation.lib.php tries to reference an associative array element that might not always exist. So for every field in the database a PHP notice is generated (undefined index.) Here's what I did to fix it:
foreach ($disp_row as $relrow) {
+ if (!isset($relrow[$foreign_field])) {
+ $value = '';
+ } else {
$key = $relrow[$foreign_field];
// if the display field has been defined for this foreign table
if ($foreign_display) {
$value = $relrow[$foreign_display];
} else {
$value = '';
} // end if ($foreign_display)
+ } // end if
$foreign[$key] = $value;
} // end foreach
Moved to patches.
Please tell me how to reproduce the case where the element does not exist.
I'm not sure what I'm doing to cause it. I'm using the InnoDB engine on my database, lots of foreign keys but none of the pma_* tables are configured or anything.
Ok, I tried with InnoDB and cannot see any notices.
Could you paste here some of the notices?
These appear when you click Search?
It looks like it's a particular table of mine that's causing the problem. It's got a foreign key pointing back to another table without any rows; the error occurs because the search page tries to draw the select box for that field. When I try to replicate this on another server, I don't get the error message (or the select box.) Trying to come up with a test case...
[Wed Sep 24 10:49:45 2008] [error] [client ::1] PHP Notice: Undefined index: up_profile_id in /opt/local/www/phpmyadmin/libraries/relation.lib.php on line 952, referer: http://localhost/phpmyadmin/tbl_structure.php?db=radius2&token=1fb292975d4e67c74293e035f4c174da&table=users
[Wed Sep 24 10:49:45 2008] [error] [client ::1] PHP Notice: Undefined index: up_profile_id in /opt/local/www/phpmyadmin/libraries/relation.lib.php on line 952, referer: http://localhost/phpmyadmin/tbl_structure.php?db=radius2&token=1fb292975d4e67c74293e035f4c174da&table=users
[Wed Sep 24 10:49:45 2008] [error] [client ::1] PHP Notice: Undefined index: up_profile_id in /opt/local/www/phpmyadmin/libraries/relation.lib.php on line 952, referer: http://localhost/phpmyadmin/tbl_structure.php?db=radius2&token=1fb292975d4e67c74293e035f4c174da&table=users
[Wed Sep 24 10:49:45 2008] [error] [client ::1] PHP Notice: Undefined index: up_profile_id in /opt/local/www/phpmyadmin/libraries/relation.lib.php on line 952, referer: http://localhost/phpmyadmin/tbl_structure.php?db=radius2&token=1fb292975d4e67c74293e035f4c174da&table=users
[Wed Sep 24 10:49:45 2008] [error] [client ::1] PHP Notice: Undefined index: up_profile_id in /opt/local/www/phpmyadmin/libraries/relation.lib.php on line 952, referer: http://localhost/phpmyadmin/tbl_structure.php?db=radius2&token=1fb292975d4e67c74293e035f4c174da&table=users
[Wed Sep 24 10:49:45 2008] [error] [client ::1] PHP Notice: Undefined index: up_profile_id in /opt/local/www/phpmyadmin/libraries/relation.lib.php on line 952, referer: http://localhost/phpmyadmin/tbl_structure.php?db=radius2&token=1fb292975d4e67c74293e035f4c174da&table=users
[Wed Sep 24 10:49:45 2008] [error] [client ::1] PHP Notice: Undefined index: up_profile_id in /opt/local/www/phpmyadmin/libraries/relation.lib.php on line 952, referer: http://localhost/phpmyadmin/tbl_structure.php?db=radius2&token=1fb292975d4e67c74293e035f4c174da&table=users
[Wed Sep 24 10:49:45 2008] [error] [client ::1] PHP Notice: Undefined index: up_profile_id in /opt/local/www/phpmyadmin/libraries/relation.lib.php on line 952, referer: http://localhost/phpmyadmin/tbl_structure.php?db=radius2&token=1fb292975d4e67c74293e035f4c174da&table=users
[Wed Sep 24 10:49:45 2008] [error] [client ::1] PHP Notice: Undefined index: up_profile_id in /opt/local/www/phpmyadmin/libraries/relation.lib.php on line 952, referer: http://localhost/phpmyadmin/tbl_structure.php?db=radius2&token=1fb292975d4e67c74293e035f4c174da&table=users
[Wed Sep 24 10:49:45 2008] [error] [client ::1] PHP Notice: Undefined index: up_profile_id in /opt/local/www/phpmyadmin/libraries/relation.lib.php on line 952, referer: http://localhost/phpmyadmin/tbl_structure.php?db=radius2&token=1fb292975d4e67c74293e035f4c174da&table=users
File Added: Picture 2.png
Here it is; seems to be triggered by the interplay between the three tables; if there's no data in table1 then the error does not occur. After this database is created, go to table2 and click search to replicate the problem. I think the focus of this bug should actually be the fact that it's trying to generate a select box when it shouldn't; something I hadn't noticed before now.
CREATE DATABASE `test2112871`;
USE `test2112871`;
SET FOREIGN_KEY_CHECKS=0;
SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO";
CREATE TABLE `table1` (`t1_id` int(10) unsigned NOT NULL auto_increment, `t1_data` varchar(64) collate latin1_general_ci NOT NULL, PRIMARY KEY (`t1_id`)) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci;
INSERT INTO `table1` (`t1_id`, `t1_data`) VALUES (1, 'data'), (2, 'other data'), (3, 'third data');
CREATE TABLE IF NOT EXISTS `table2` (`t2_id` int(10) unsigned NOT NULL auto_increment, `t1_id` int(10) unsigned NOT NULL, `t3_id` int(10) unsigned default NULL, PRIMARY KEY (`t2_id`), KEY `fk_t1_id` (`t1_id`), KEY `fk_t3_id` (`t3_id`)) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci;
CREATE TABLE IF NOT EXISTS `table3` (`t3_id` int(10) unsigned NOT NULL auto_increment, `t1_id` int(10) unsigned NOT NULL, `up_desc` varchar(64) collate latin1_general_ci NOT NULL, PRIMARY KEY (`t3_id`), KEY `fk_t1_id` (`t1_id`)) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci;
ALTER TABLE `table2` ADD CONSTRAINT `table2_ibfk_1` FOREIGN KEY (`t1_id`) REFERENCES `table1` (`t1_id`) ON DELETE CASCADE ON UPDATE CASCADE, ADD CONSTRAINT `table2_ibfk_2` FOREIGN KEY (`t3_id`) REFERENCES `table3` (`t3_id`) ON DELETE CASCADE ON UPDATE CASCADE;
ALTER TABLE `table3` ADD CONSTRAINT `table3_ibfk_1` FOREIGN KEY (`t1_id`) REFERENCES `table1` (`t1_id`) ON DELETE CASCADE ON UPDATE CASCADE;
SET FOREIGN_KEY_CHECKS=1;
I hate to reply that but with your test case I cannot reproduce the problem (tested with trunk).
Modifying the code like this:
foreach ($disp_row as $relrow) {
echo 'trace ' . $foreign_field . ' ' . $relrow[$foreign_field] . "\n";
$key = $relrow[$foreign_field];
Going to table2 and clicking Search, I get (with PHP 5.2.6):
trace t1_id 1
trace t1_id 2
trace t1_id 3
Just checked out SVN trunk and I don't see the error either. The search page shows a textbox for t3_id search field, as it should, not a corrupted select box like 2.11.9 does.
I'll close this; I assume it's not worth the trouble to fix this on the 2.11 branch. Sorry to take your time!
Mike,
thanks anyway for your good work!