📄 tbl_relation.php
字号:
. ' WHERE db_name = \'' . PMA_sqlAddslashes($db) . '\'' . ' AND table_name = \'' . PMA_sqlAddslashes($table) . '\''; } else { $upd_query = 'DELETE FROM ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($cfgRelation['table_info']) . ' WHERE db_name = \'' . PMA_sqlAddslashes($db) . '\'' . ' AND table_name = \'' . PMA_sqlAddslashes($table) . '\''; } } elseif ($display_field != '') { $upd_query = 'INSERT INTO ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($cfgRelation['table_info']) . '(db_name, table_name, display_field) ' . ' VALUES(' . '\'' . PMA_sqlAddslashes($db) . '\',' . '\'' . PMA_sqlAddslashes($table) . '\',' . '\'' . PMA_sqlAddslashes($display_field) . '\')'; } if ($upd_query) { PMA_query_as_cu($upd_query); }} // end if// If we did an update, refresh our dataif (isset($destination) && $cfgRelation['relwork']) { $existrel = PMA_getForeigners($db, $table, '', 'internal');}if (isset($destination_foreign) && PMA_foreignkey_supported($tbl_type)) { $existrel_foreign = PMA_getForeigners($db, $table, '', 'foreign');}if ($cfgRelation['displaywork']) { $disp = PMA_getDisplayField($db, $table);}/** * Dialog */// common formecho '<form method="post" action="tbl_relation.php">' . "\n";echo PMA_generate_common_hidden_inputs($db, $table);// relationsif ($cfgRelation['relwork'] || PMA_foreignkey_supported($tbl_type)) { // To choose relations we first need all tables names in current db // and if the main table supports foreign keys // we use SHOW TABLE STATUS because we need to find other tables of the // same engine. if (PMA_foreignkey_supported($tbl_type)) { $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[] = ''; $selectboxall_foreign[] = ''; while ($curr_table = PMA_DBI_fetch_row($tab_rs)) { $current_table = new PMA_Table($curr_table[0], $db); // explicitely ask for non-quoted list of indexed columns $selectboxall = array_merge($selectboxall, $current_table->getUniqueColumns(false)); // if foreign keys are supported, collect all keys from other // tables of the same engine if (PMA_foreignkey_supported($tbl_type) && isset($curr_table[1]) && strtoupper($curr_table[1]) == $tbl_type) { // explicitely ask for non-quoted list of indexed columns $selectboxall_foreign = array_merge($selectboxall_foreign, $current_table->getIndexedColumns(false)); } } // 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 (PMA_foreignkey_supported($tbl_type)) { echo PMA_showHint($strInternalAndForeign); } echo '</th>'; } if (PMA_foreignkey_supported($tbl_type)) { // this does not have to be translated, it's part of the MySQL syntax echo '<th colspan="2">FOREIGN KEY (' . $tbl_type . ')'; 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"> <strong><?php echo $save_row[$i]['Field']; ?></strong></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 $value) { echo ' ' . '<option value="' . htmlspecialchars($value) . '"'; if ($foreign_field && $value == $foreign_field) { echo ' selected="selected"'; $seen_key = TRUE; } echo '>' . htmlspecialchars($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 (PMA_foreignkey_supported($tbl_type)) { echo '<td>'; if (!empty($save_row[$i]['Key'])) { ?> <span class="formelement"> <select name="destination_foreign[<?php echo htmlspecialchars($save_row[$i]['Field']); ?>]"> <?php if (isset($existrel_foreign[$myfield])) { $foreign_field = $existrel_foreign[$myfield]['foreign_db'] . '.' . $existrel_foreign[$myfield]['foreign_table'] . '.' . $existrel_foreign[$myfield]['foreign_field']; } else { $foreign_field = FALSE; } $found_foreign_field = FALSE; foreach ($selectboxall_foreign as $value) { echo ' ' . '<option value="' . htmlspecialchars($value) . '"'; if ($foreign_field && $value == $foreign_field) { echo ' selected="selected"'; $found_foreign_field = TRUE; } echo '>' . htmlspecialchars($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[' . $save_row[$i]['Field'] . ']', $options_array, isset($existrel_foreign[$myfield]['on_delete']) ? $existrel_foreign[$myfield]['on_delete']: ''); echo '</span>' . "\n" .'<span class="formelement">' . "\n"; PMA_generate_dropdown('ON UPDATE', 'on_update[' . $save_row[$i]['Field'] . ']', $options_array, isset($existrel_foreign[$myfield]['on_update']) ? $existrel_foreign[$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)/** * Displays the footer */require_once './libraries/footer.inc.php';?>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -