📄 tbl_relation.php
字号:
*/// common formecho '<form method="post" action="tbl_relation.php">' . "\n";echo PMA_generate_common_hidden_inputs($db, $table);// relationsif ($cfgRelation['relwork'] || $tbl_type=='INNODB') { // To choose relations we first need all tables names in current db // and if PMA version permits and the main table is innodb, // we use SHOW TABLE STATUS because we need to find other InnoDB tables if ($tbl_type=='INNODB') { $tab_query = 'SHOW TABLE STATUS FROM ' . PMA_backquote($db); // [0] of the row is the name // [1] is the type } else { $tab_query = 'SHOW TABLES FROM ' . PMA_backquote($db); } // [0] of the row is the name $tab_rs = PMA_DBI_query($tab_query, null, PMA_DBI_QUERY_STORE); $selectboxall['nix'] = '--'; $selectboxall_innodb['nix'] = '--'; while ($curr_table = @PMA_DBI_fetch_row($tab_rs)) { if (($curr_table[0] != $table) && ($curr_table[0] != $cfg['Server']['relation'])) { PMA_DBI_select_db($db); // need to use PMA_DBI_QUERY_STORE with PMA_DBI_num_rows() in mysqli $fi_rs = PMA_DBI_query('SHOW KEYS FROM ' . PMA_backquote($curr_table[0]) . ';', null, PMA_DBI_QUERY_STORE); if ($fi_rs && PMA_DBI_num_rows($fi_rs) > 0) { $seen_a_primary = FALSE; while ($curr_field = PMA_DBI_fetch_assoc($fi_rs)) { if (isset($curr_field['Key_name']) && $curr_field['Key_name'] == 'PRIMARY') { $seen_a_primary = TRUE; $field_full = $db . '.' .$curr_field['Table'] . '.' . $curr_field['Column_name']; $field_v = $curr_field['Table'] . '->' . $curr_field['Column_name']; $selectboxall[$field_full] = $field_v; // there could be more than one segment of the primary // so do not break // Please watch here, tbl_type is INNODB but the // resulting value of SHOW KEYS is InnoDB if ($tbl_type=='INNODB' && isset($curr_table[1]) && $curr_table[1]=='InnoDB') { $selectboxall_innodb[$field_full] = $field_v; } } elseif (isset($curr_field['Non_unique']) && $curr_field['Non_unique'] == 0 && $seen_a_primary==FALSE) { // if we can't find a primary key we take any unique one // (in fact, we show all segments of unique keys // and all unique keys) $field_full = $db . '.' . $curr_field['Table'] . '.' . $curr_field['Column_name']; $field_v = $curr_field['Table'] . '->' . $curr_field['Column_name']; $selectboxall[$field_full] = $field_v; if ($tbl_type=='INNODB' && isset($curr_table[1]) && $curr_table[1]=='InnoDB') { $selectboxall_innodb[$field_full] = $field_v; } // for InnoDB, any index is allowed } elseif ($tbl_type=='INNODB' && isset($curr_table[1]) && $curr_table[1]=='InnoDB') { $field_full = $db . '.' . $curr_field['Table'] . '.' . $curr_field['Column_name']; $field_v = $curr_field['Table'] . '->' . $curr_field['Column_name']; $selectboxall_innodb[$field_full] = $field_v; } // end if } // end while over keys } // end if (PMA_DBI_num_rows) PMA_DBI_free_result($fi_rs); unset($fi_rs); // Mike Beck - 24.07.02: i've been asked to add all keys of the // current table (see bug report #574851) } elseif ($curr_table[0] == $table) { PMA_DBI_select_db($db); // need to use PMA_DBI_QUERY_STORE with PMA_DBI_num_rows() in mysqli $fi_rs = PMA_DBI_query('SHOW KEYS FROM ' . PMA_backquote($curr_table[0]) . ';', null, PMA_DBI_QUERY_STORE); if ($fi_rs && PMA_DBI_num_rows($fi_rs) > 0) { while ($curr_field = PMA_DBI_fetch_assoc($fi_rs)) { $field_full = $db . '.' . $curr_field['Table'] . '.' . $curr_field['Column_name']; $field_v = $curr_field['Table'] . '->' . $curr_field['Column_name']; $selectboxall[$field_full] = $field_v; if ($tbl_type=='INNODB' && isset($curr_table[1]) && $curr_table[1]=='InnoDB') { $selectboxall_innodb[$field_full] = $field_v; } } // end while } // end if (PMA_DBI_num_rows) PMA_DBI_free_result($fi_rs); unset($fi_rs); } } // end while over tables} // end if// Now find out the columns of our $table// need to use PMA_DBI_QUERY_STORE with PMA_DBI_num_rows() in mysqli$col_rs = PMA_DBI_try_query('SHOW COLUMNS FROM ' . PMA_backquote($table) . ';', null, PMA_DBI_QUERY_STORE);if ($col_rs && PMA_DBI_num_rows($col_rs) > 0) { while ($row = PMA_DBI_fetch_assoc($col_rs)) { $save_row[] = $row; } $saved_row_cnt = count($save_row); ?> <fieldset> <legend><?php echo $strLinksTo; ?></legend> <table> <tr><th></th> <?php if ( $cfgRelation['relwork'] ) { echo '<th>' . $strInternalRelations; if ($tbl_type=='INNODB') { echo PMA_showHint( $strInternalNotNecessary ); } echo '</th>'; } if ( $tbl_type=='INNODB' ) { echo '<th colspan="2">InnoDB'; if (PMA_MYSQL_INT_VERSION < 40013) { echo '(**)'; } echo '</th>'; } ?> </tr> <?php $odd_row = true; for ($i = 0; $i < $saved_row_cnt; $i++) { $myfield = $save_row[$i]['Field']; ?> <tr class="<?php echo $odd_row ? 'odd' : 'even'; $odd_row = ! $odd_row; ?>"> <td align="center"> <b><?php echo $save_row[$i]['Field']; ?></b></td> <?php if ($cfgRelation['relwork']) { ?> <td><select name="destination[<?php echo htmlspecialchars($save_row[$i]['Field']); ?>]"> <?php // PMA internal relations if (isset($existrel[$myfield])) { $foreign_field = $existrel[$myfield]['foreign_db'] . '.' . $existrel[$myfield]['foreign_table'] . '.' . $existrel[$myfield]['foreign_field']; } else { $foreign_field = FALSE; } $seen_key = FALSE; foreach ($selectboxall AS $key => $value) { echo ' ' . '<option value="' . htmlspecialchars($key) . '"'; if ($foreign_field && $key == $foreign_field) { echo ' selected="selected"'; $seen_key = TRUE; } echo '>' . $value . '</option>'. "\n"; } // end while // if the link defined in relationtable points to a foreign field // that is not a key in the foreign table, we show the link // (will not be shown with an arrow) if ($foreign_field && !$seen_key) { echo ' ' .'<option value="' . htmlspecialchars($foreign_field) . '"' .' selected="selected"' .'>' . $foreign_field . '</option>'. "\n"; } ?> </select> </td> <?php } // end if (internal relations) if ($tbl_type=='INNODB') { echo '<td>'; if (!empty($save_row[$i]['Key'])) { ?> <span class="formelement"> <select name="destination_innodb[<?php echo htmlspecialchars($save_row[$i]['Field']); ?>]"> <?php if (isset($existrel_innodb[$myfield])) { $foreign_field = $existrel_innodb[$myfield]['foreign_db'] . '.' . $existrel_innodb[$myfield]['foreign_table'] . '.' . $existrel_innodb[$myfield]['foreign_field']; } else { $foreign_field = FALSE; } $found_foreign_field = FALSE; foreach ($selectboxall_innodb AS $key => $value) { echo ' ' . '<option value="' . htmlspecialchars($key) . '"'; if ($foreign_field && $key == $foreign_field) { echo ' selected="selected"'; $found_foreign_field = TRUE; } echo '>' . $value . '</option>'. "\n"; } // end while // we did not find the foreign field in the tables of current db, // must be defined in another db so show it to avoid erasing it if (!$found_foreign_field && $foreign_field) { echo ' ' . '<option value="' . htmlspecialchars($foreign_field) . '"'; echo ' selected="selected"'; echo '>' . $foreign_field . '</option>' . "\n"; } ?> </select> </span> <span class="formelement"> <?php PMA_generate_dropdown('ON DELETE', 'on_delete[' . htmlspecialchars($save_row[$i]['Field']) . ']', $options_array, isset($existrel_innodb[$myfield]['on_delete']) ? $existrel_innodb[$myfield]['on_delete']: '' ); echo '</span>' . "\n" .'<span class="formelement">' . "\n"; PMA_generate_dropdown('ON UPDATE', 'on_update[' . htmlspecialchars($save_row[$i]['Field']) . ']', $options_array, isset($existrel_innodb[$myfield]['on_update']) ? $existrel_innodb[$myfield]['on_update']: '' ); echo '</span>' . "\n"; } else { echo $strNoIndex; } // end if (a key exists) echo ' </td>'; } // end if (InnoDB) ?> </tr> <?php } // end for echo ' </table>' . "\n"; echo '</fieldset>' . "\n"; if ($cfgRelation['displaywork']) { // Get "display_field" infos $disp = PMA_getDisplayField($db, $table); ?> <fieldset> <label><?php echo $strChangeDisplay . ': '; ?></label> <select name="display_field" style="vertical-align: middle"> <option value="">---</option> <?php foreach ($save_row AS $row) { echo ' <option value="' . htmlspecialchars($row['Field']) . '"'; if (isset($disp) && $row['Field'] == $disp) { echo ' selected="selected"'; } echo '>' . htmlspecialchars($row['Field']) . '</option>'. "\n"; } // end while ?> </select> </fieldset> <?php } // end if (displayworks) ?> <fieldset class="tblFooters"> <input type="submit" value="<?php echo $strSave; ?>" /> </fieldset></form> <?php} // end if (we have columns in this table)if ( $tbl_type === 'INNODB' && PMA_MYSQL_INT_VERSION < 40013 ) { echo '<div class="warning">' .'** ' . sprintf($strUpgrade, 'MySQL', '4.0.13') .'</div>';}/** * Displays the footer */require_once('./libraries/footer.inc.php');?>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -