📄 relation.lib.php
字号:
if (count($one_key['index_list']) == 1) { foreach ($one_key['index_list'] as $i => $field) { // If a foreign key is defined in the 'internal' source (pmadb) // and as a native foreign key, we won't get it twice // if $source='both' because we use $field as key // The parser looks for a CONSTRAINT clause just before // the FOREIGN KEY clause. It finds it (as output from // SHOW CREATE TABLE) in MySQL 4.0.13, but not in older // versions like 3.23.58. // In those cases, the FOREIGN KEY parsing will put numbers // like -1, 0, 1... instead of the constraint number. if (isset($one_key['constraint'])) { $foreign[$field]['constraint'] = $one_key['constraint']; } if (isset($one_key['ref_db_name'])) { $foreign[$field]['foreign_db'] = $one_key['ref_db_name']; } else { $foreign[$field]['foreign_db'] = $db; } $foreign[$field]['foreign_table'] = $one_key['ref_table_name']; $foreign[$field]['foreign_field'] = $one_key['ref_index_list'][$i]; if (isset($one_key['on_delete'])) { $foreign[$field]['on_delete'] = $one_key['on_delete']; } if (isset($one_key['on_update'])) { $foreign[$field]['on_update'] = $one_key['on_update']; } } } } } /** * Emulating relations for some information_schema tables */ if ($db == 'information_schema' && ($source == 'internal' || $source == 'both')) { require_once './libraries/information_schema_relations.lib.php'; if (isset($GLOBALS['information_schema_relations'][$table])) { foreach ($GLOBALS['information_schema_relations'][$table] as $field => $relations) { if ((! strlen($column) || $column == $field) && (! isset($foreign[$field]) || ! strlen($foreign[$field]))) { $foreign[$field] = $relations; } } } } return $foreign;} // end of the 'PMA_getForeigners()' function/** * Gets the display field of a table * * @access public * @author Mike Beck <mikebeck@users.sourceforge.net> * @uses $GLOBALS['controllink'] * @uses PMA_getRelationsParam() * @uses PMA_backquote() * @uses PMA_sqlAddslashes() * @uses PMA_DBI_fetch_single_row() * @uses trim() * @param string $db the name of the db to check for * @param string $table the name of the table to check for * @return string field name */function PMA_getDisplayField($db, $table){ $cfgRelation = PMA_getRelationsParam(); /** * Try to fetch the display field from DB. */ if ($cfgRelation['displaywork']) { $disp_query = ' SELECT `display_field` FROM ' . PMA_backquote($cfgRelation['db']) . '.' . PMA_backquote($cfgRelation['table_info']) . ' WHERE `db_name` = \'' . PMA_sqlAddslashes($db) . '\' AND `table_name` = \'' . PMA_sqlAddslashes($table) . '\''; $row = PMA_DBI_fetch_single_row($disp_query, 'ASSOC', $GLOBALS['controllink']); if (isset($row['display_field'])) { return $row['display_field']; } } /** * Emulating the display field for some information_schema tables. */ if ($db == 'information_schema') { switch ($table) { case 'CHARACTER_SETS': return 'DESCRIPTION'; case 'TABLES': return 'TABLE_COMMENT'; } } /** * No Luck... */ return false;} // end of the 'PMA_getDisplayField()' function/** * Gets the comments for all rows of a table or the db itself * * @author Mike Beck <mikebeck@users.sourceforge.net> * @author lem9 * @access public * @uses PMA_DBI_get_fields() * @uses PMA_getDbComment() * @param string the name of the db to check for * @param string the name of the table to check for * @return array [field_name] = comment */function PMA_getComments($db, $table = ''){ $comments = array(); if ($table != '') { // MySQL native column comments $fields = PMA_DBI_get_fields($db, $table); if ($fields) { foreach ($fields as $key => $field) { if (! empty($field['Comment'])) { $comments[$field['Field']] = $field['Comment']; } } } } else { $comments[] = PMA_getDbComment($db); } return $comments;} // end of the 'PMA_getComments()' function/** * Gets the comment for a db * * @author Mike Beck <mikebeck@users.sourceforge.net> * @author lem9 * @access public * @uses PMA_DBI_QUERY_STORE * @uses PMA_DBI_num_rows() * @uses PMA_DBI_fetch_assoc() * @uses PMA_DBI_free_result() * @uses PMA_getRelationsParam() * @uses PMA_backquote() * @uses PMA_sqlAddslashes() * @uses PMA_query_as_cu() * @uses strlen() * @param string the name of the db to check for * @return string comment */function PMA_getDbComment($db){ $cfgRelation = PMA_getRelationsParam(); $comment = ''; if ($cfgRelation['commwork']) { // pmadb internal db comment $com_qry = " SELECT `comment` FROM " . PMA_backquote($cfgRelation['db']) . "." . PMA_backquote($cfgRelation['column_info']) . " WHERE db_name = '" . PMA_sqlAddslashes($db) . "' AND table_name = '' AND column_name = '(db_comment)'"; $com_rs = PMA_query_as_cu($com_qry, true, PMA_DBI_QUERY_STORE); if ($com_rs && PMA_DBI_num_rows($com_rs) > 0) { $row = PMA_DBI_fetch_assoc($com_rs); $comment = $row['comment']; } PMA_DBI_free_result($com_rs); } return $comment;} // end of the 'PMA_getDbComment()' function/** * Gets the comment for a db * * @author Mike Beck <mikebeck@users.sourceforge.net> * @author lem9 * @access public * @uses PMA_DBI_QUERY_STORE * @uses PMA_DBI_num_rows() * @uses PMA_DBI_fetch_assoc() * @uses PMA_DBI_free_result() * @uses PMA_getRelationsParam() * @uses PMA_backquote() * @uses PMA_sqlAddslashes() * @uses PMA_query_as_cu() * @uses strlen() * @param string the name of the db to check for * @return string comment */function PMA_getDbComments(){ $cfgRelation = PMA_getRelationsParam(); $comments = array(); if ($cfgRelation['commwork']) { // pmadb internal db comment $com_qry = " SELECT `db_name`, `comment` FROM " . PMA_backquote($cfgRelation['db']) . "." . PMA_backquote($cfgRelation['column_info']) . " WHERE `column_name` = '(db_comment)'"; $com_rs = PMA_query_as_cu($com_qry, true, PMA_DBI_QUERY_STORE); if ($com_rs && PMA_DBI_num_rows($com_rs) > 0) { while ($row = PMA_DBI_fetch_assoc($com_rs)) { $comments[$row['db_name']] = $row['comment']; } } PMA_DBI_free_result($com_rs); } return $comments;} // end of the 'PMA_getDbComments()' function/** * Set a database comment to a certain value. * * @uses PMA_getRelationsParam() * @uses PMA_backquote() * @uses PMA_sqlAddslashes() * @uses PMA_query_as_cu() * @uses strlen() * @access public * @param string $db the name of the db * @param string $comment the value of the column * @return boolean true, if comment-query was made. */function PMA_setDbComment($db, $comment = ''){ $cfgRelation = PMA_getRelationsParam(); if (! $cfgRelation['commwork']) { return false; } if (strlen($comment)) { $upd_query = " INSERT INTO " . PMA_backquote($cfgRelation['db']) . "." . PMA_backquote($cfgRelation['column_info']) . " (`db_name`, `table_name`, `column_name`, `comment`) VALUES ( '" . PMA_sqlAddslashes($db) . "', '', '(db_comment)', '" . PMA_sqlAddslashes($comment) . "') ON DUPLICATE KEY UPDATE `comment` = '" . PMA_sqlAddslashes($comment) . "'"; } else { $upd_query = ' DELETE FROM ' . PMA_backquote($cfgRelation['db']) . '.' . PMA_backquote($cfgRelation['column_info']) . ' WHERE `db_name` = \'' . PMA_sqlAddslashes($db) . '\' AND `table_name` = \'\' AND `column_name` = \'(db_comment)\''; } if (isset($upd_query)){ return PMA_query_as_cu($upd_query); } return false;} // end of 'PMA_setDbComment()' function/** * Set a SQL history entry * * @uses $_SESSION['sql_history'] * @uses $cfg['QueryHistoryMax'] * @uses PMA_getRelationsParam() * @uses PMA_query_as_cu() * @uses PMA_backquote() * @uses PMA_sqlAddslashes() * @uses count() * @uses md5() * @uses array_shift() * @param string $db the name of the db * @param string $table the name of the table * @param string $username the username * @param string $sqlquery the sql query * @access public */function PMA_setHistory($db, $table, $username, $sqlquery){ if (strlen($sqlquery) > $GLOBALS['cfg']['MaxCharactersInDisplayedSQL']) { return; } $cfgRelation = PMA_getRelationsParam(); if (! isset($_SESSION['sql_history'])) { $_SESSION['sql_history'] = array(); } $key = md5($sqlquery . $db . $table); if (isset($_SESSION['sql_history'][$key])) { unset($_SESSION['sql_history'][$key]); } $_SESSION['sql_history'][$key] = array( 'db' => $db, 'table' => $table, 'sqlquery' => $sqlquery, ); if (count($_SESSION['sql_history']) > $GLOBALS['cfg']['QueryHistoryMax']) { // history should not exceed a maximum count array_shift($_SESSION['sql_history']); } if (! $cfgRelation['historywork']) { return; } PMA_query_as_cu(' INSERT INTO ' . PMA_backquote($cfgRelation['db']) . '.' . PMA_backquote($cfgRelation['history']) . ' (`username`, `db`, `table`, `timevalue`, `sqlquery`) VALUES (\'' . PMA_sqlAddslashes($username) . '\', \'' . PMA_sqlAddslashes($db) . '\', \'' . PMA_sqlAddslashes($table) . '\', NOW(), \'' . PMA_sqlAddslashes($sqlquery) . '\')');} // end of 'PMA_setHistory()' function/** * Gets a SQL history entry * * @uses $_SESSION['sql_history'] * @uses $GLOBALS['controllink'] * @uses PMA_getRelationsParam() * @uses PMA_backquote() * @uses PMA_sqlAddslashes() * @uses PMA_DBI_fetch_result() * @uses array_reverse() * @param string $username the username * @return array list of history items * @access public */function PMA_getHistory($username){ $cfgRelation = PMA_getRelationsParam(); if (isset($_SESSION['sql_history'])) { return array_reverse($_SESSION['sql_history']); } if (! $cfgRelation['historywork']) { return false; } $hist_query = ' SELECT `db`, `table`, `sqlquery` FROM ' . PMA_backquote($cfgRelation['db']) . '.' . PMA_backquote($cfgRelation['history']) . ' WHERE `username` = \'' . PMA_sqlAddslashes($username) . '\' ORDER BY `id` DESC'; return PMA_DBI_fetch_result($hist_query, null, null, $GLOBALS['controllink']);} // end of 'PMA_getHistory()' function/** * purges SQL history * * deletes entries that exceeds $cfg['QueryHistoryMax'], oldest first, for the * given user * * @uses $cfg['QueryHistoryMax'] * @uses $cfg['QueryHistoryDB'] * @uses $GLOBALS['controllink'] * @uses PMA_backquote() * @uses PMA_sqlAddSlashes() * @uses PMA_query_as_cu()
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -