common.lib.php
来自「php绿色服务器,让大家试用greenamp」· PHP 代码 · 共 1,687 行 · 第 1/5 页
PHP
1,687 行
$num_dbs = count($dblist); // 1. A list of allowed databases has already been defined by the // authentification process -> gets the available databases list if ($num_dbs) { $true_dblist = array(); for ($i = 0; $i < $num_dbs; $i++) { $dblink = @PMA_DBI_select_db($dblist[$i]); if ($dblink) { $true_dblist[] = $dblist[$i]; } // end if } // end for $dblist = array(); $dblist = $true_dblist; unset($true_dblist); $num_dbs = count($dblist); } // end if // 2. Allowed database list is empty -> gets the list of all databases // on the server else if (!isset($cfg['Server']['only_db']) || $cfg['Server']['only_db'] == '') { $dblist = PMA_DBI_get_dblist(); // needed? or PMA_mysqlDie('', 'SHOW DATABASES;', FALSE, $error_url); $num_dbs = count($dblist); } // end else return TRUE; } // end of the 'PMA_availableDatabases()' function /* ----------------------- Set of misc functions ----------------------- */ /** * Adds backquotes on both sides of a database, table or field name. * Since MySQL 3.23.6 this allows to use non-alphanumeric characters in * these names. * * @param mixed the database, table or field name to "backquote" or * array of it * @param boolean a flag to bypass this function (used by dump * functions) * * @return mixed the "backquoted" database, table or field name if the * current MySQL release is >= 3.23.6, the original one * else * * @access public */ function PMA_backquote($a_name, $do_it = TRUE) { if ($do_it && !empty($a_name) && $a_name != '*') { if (is_array($a_name)) { $result = array(); foreach ($a_name AS $key => $val) { $result[$key] = '`' . $val . '`'; } return $result; } else { return '`' . $a_name . '`'; } } else { return $a_name; } } // end of the 'PMA_backquote()' function /** * Format a string so it can be passed to a javascript function. * This function is used to displays a javascript confirmation box for * "DROP/DELETE/ALTER" queries. * * @param string the string to format * @param boolean whether to add backquotes to the string or not * * @return string the formated string * * @access public */ function PMA_jsFormat($a_string = '', $add_backquotes = TRUE) { if (is_string($a_string)) { $a_string = htmlspecialchars($a_string); $a_string = str_replace('\\', '\\\\', $a_string); $a_string = str_replace('\'', '\\\'', $a_string); $a_string = str_replace('#', '\\#', $a_string); $a_string = str_replace("\012", '\\\\n', $a_string); $a_string = str_replace("\015", '\\\\r', $a_string); } return (($add_backquotes) ? PMA_backquote($a_string) : $a_string); } // end of the 'PMA_jsFormat()' function /** * Defines the <CR><LF> value depending on the user OS. * * @return string the <CR><LF> value to use * * @access public */ function PMA_whichCrlf() { $the_crlf = "\n"; // The 'PMA_USR_OS' constant is defined in "./libraries/defines.lib.php" // Win case if (PMA_USR_OS == 'Win') { $the_crlf = "\r\n"; } // Mac case else if (PMA_USR_OS == 'Mac') { $the_crlf = "\r"; } // Others else { $the_crlf = "\n"; } return $the_crlf; } // end of the 'PMA_whichCrlf()' function /** * Counts and displays the number of records in a table * * Last revision 13 July 2001: Patch for limiting dump size from * vinay@sanisoft.com & girish@sanisoft.com * * @param string the current database name * @param string the current table name * @param boolean whether to retain or to displays the result * * @return mixed the number of records if retain is required, true else * * @access public */ function PMA_countRecords($db, $table, $ret = FALSE) { global $err_url, $cfg; $result = PMA_DBI_query('SHOW TABLE STATUS FROM ' . PMA_backquote($db) . ' LIKE \'' . PMA_sqlAddslashes($table, TRUE) . '\';'); $showtable = PMA_DBI_fetch_assoc($result); $num = (isset($showtable['Rows']) ? $showtable['Rows'] : 0); if ($num < $cfg['MaxExactCount']) { unset($num); } PMA_DBI_free_result($result); if (!isset($num)) { $result = PMA_DBI_query('SELECT COUNT(*) AS num FROM ' . PMA_backquote($db) . '.' . PMA_backquote($table)); list($num) = ($result) ? PMA_DBI_fetch_row($result) : array(0); PMA_DBI_free_result($result); } if ($ret) { return $num; } else { echo number_format($num, 0, $GLOBALS['number_decimal_separator'], $GLOBALS['number_thousands_separator']); return TRUE; } } // end of the 'PMA_countRecords()' function /** * Sanitizes $message, taking into account our special codes * for formatting * * @param string the message * * @return string the sanitized message * * @access public */ function PMA_sanitize($message) { $replace_pairs = array( '<' => '<', '>' => '>', '[i]' => '<i>', '[/i]' => '</i>', '[b]' => '<b>', '[br]' => '<br />', '[/b]' => '</b>', ); return strtr($message, $replace_pairs); } /** * Displays a message at the top of the "main" (right) frame * * @param string the message to display * * @global array the configuration array * * @access public */ function PMA_showMessage($message) { global $cfg; // Sanitizes $message $message = PMA_sanitize($message); require_once('./header.inc.php'); // Reloads the navigation frame via JavaScript if required if (isset($GLOBALS['reload']) && $GLOBALS['reload']) { echo "\n"; $reload_url = './left.php?' . PMA_generate_common_url((isset($GLOBALS['db']) ? $GLOBALS['db'] : ''), '', '&') ?><script type="text/javascript" language="javascript1.2"><!--if (typeof(window.parent) != 'undefined' && typeof(window.parent.frames['nav']) != 'undefined') { window.parent.frames['nav'].goTo('<?php echo $reload_url; ?>&hash=' + <?php echo (($cfg['QueryFrame'] && $cfg['QueryFrameJS']) ? 'window.parent.frames[\'queryframe\'].document.hashform.hash.value' : "'" . md5($cfg['PmaAbsoluteUri']) . "'"); ?>);}//--></script> <?php unset($GLOBALS['reload']); } // Corrects the tooltip text via JS if required else if (!empty($GLOBALS['table']) && $cfg['ShowTooltip']) { $result = PMA_DBI_try_query('SHOW TABLE STATUS FROM ' . PMA_backquote($GLOBALS['db']) . ' LIKE \'' . PMA_sqlAddslashes($GLOBALS['table'], TRUE) . '\''); if ($result) { $tbl_status = PMA_DBI_fetch_assoc($result); $tooltip = (empty($tbl_status['Comment'])) ? '' : $tbl_status['Comment'] . ' '; $tooltip .= '(' . $tbl_status['Rows'] . ' ' . $GLOBALS['strRows'] . ')'; PMA_DBI_free_result($result); $md5_tbl = md5($GLOBALS['table']); echo "\n"; ?><script type="text/javascript" language="javascript1.2"><!--if (typeof(document.getElementById) != 'undefined' && typeof(window.parent.frames['nav']) != 'undefined' && typeof(window.parent.frames['nav'].document) != 'undefined' && typeof(window.parent.frames['nav'].document) != 'unknown' && (window.parent.frames['nav'].document.getElementById('<?php echo 'tbl_' . $md5_tbl; ?>')) && typeof(window.parent.frames['nav'].document.getElementById('<?php echo 'tbl_' . $md5_tbl; ?>')) != 'undefined' && typeof(window.parent.frames['nav'].document.getElementById('<?php echo 'tbl_' . $md5_tbl; ?>').title) == 'string') { window.parent.frames['nav'].document.getElementById('<?php echo 'tbl_' . $md5_tbl; ?>').title = '<?php echo PMA_jsFormat($tooltip, FALSE); ?>';}//--></script> <?php } // end if } // end if... else if // Checks if the table needs to be repaired after a TRUNCATE query. if (isset($GLOBALS['table']) && isset($GLOBALS['sql_query']) && $GLOBALS['sql_query'] == 'TRUNCATE TABLE ' . PMA_backquote($GLOBALS['table'])) { if (!isset($tbl_status)) { $result = @PMA_DBI_try_query('SHOW TABLE STATUS FROM ' . PMA_backquote($GLOBALS['db']) . ' LIKE \'' . PMA_sqlAddslashes($GLOBALS['table'], TRUE) . '\''); if ($result) { $tbl_status = PMA_DBI_fetch_assoc($result); PMA_DBI_free_result($result); } } if (isset($tbl_status) && (int) $tbl_status['Index_length'] > 1024) { PMA_DBI_try_query('REPAIR TABLE ' . PMA_backquote($GLOBALS['table'])); } } unset($tbl_status); echo "\n"; ?><div align="<?php echo $GLOBALS['cell_align_left']; ?>"> <table border="<?php echo $cfg['Border']; ?>" cellpadding="5" cellspacing="1"> <tr> <th<?php echo ($GLOBALS['theme'] != 'original') ? ' class="tblHeaders"' : ' bgcolor="' . $cfg['ThBgcolor'] . '"'; ?>> <b><?php echo $message; ?></b> </th> </tr> <?php if ($cfg['ShowSQL'] == TRUE && (!empty($GLOBALS['sql_query']) || !empty($GLOBALS['display_query']))) { $local_query = !empty($GLOBALS['display_query']) ? $GLOBALS['display_query'] : (($cfg['SQP']['fmtType'] == 'none' && isset($GLOBALS['unparsed_sql']) && $GLOBALS['unparsed_sql'] != '') ? $GLOBALS['unparsed_sql'] : $GLOBALS['sql_query']); // Basic url query part $url_qpart = '?' . PMA_generate_common_url(isset($GLOBALS['db']) ? $GLOBALS['db'] : '', isset($GLOBALS['table']) ? $GLOBALS['table'] : ''); echo "\n"; ?> <tr> <td bgcolor="<?php echo $cfg['BgcolorOne']; ?>"> <?php echo "\n"; // Html format the query to be displayed // The nl2br function isn't used because its result isn't a valid // xhtml1.0 statement before php4.0.5 ("<br>" and not "<br />") // If we want to show some sql code it is easiest to create it here /* SQL-Parser-Analyzer */ $sqlnr = 1; if (!empty($GLOBALS['show_as_php'])) { $new_line = '\'<br />' . "\n" . ' . \' '; } if (isset($new_line)) { /* SQL-Parser-Analyzer */ $query_base = PMA_sqlAddslashes(htmlspecialchars($local_query)); /* SQL-Parser-Analyzer */ $query_base = preg_replace("@((\015\012)|(\015)|(\012))+@", $new_line, $query_base); } else { $query_base = $local_query; } // Here we append the LIMIT added for navigation, to // enable its display. Adding it higher in the code // to $local_query would create a problem when // using the Refresh or Edit links. // Only append it on SELECTs. // FIXME: what would be the best to do when someone // hits Refresh: use the current LIMITs ? // TODO: use the parser instead of preg_match() if (preg_match('@^SELECT[[:space:]]+@i', $query_base) && isset($GLOBALS['sql_limit_to_append'])) { $query_base .= $GLOBALS['sql_limit_to_append']; } if (!empty($GLOBALS['show_as_php'])) { $query_base = '$sql = \'' . $query_base; } else if (!empty($GLOBALS['validatequery'])) { $query_base = PMA_validateSQL($query_base); } else { $parsed_sql = PMA_SQP_parse($query_base); $query_base = PMA_formatSql($parsed_sql, $query_base); } // Prepares links that may be displayed to edit/explain the query // (don't go to default pages, we must go to the page // where the query box is available) // (als
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?