📄 common.lib.php
字号:
* @param string $uri the header to send * @return boolean always true */ function PMA_sendHeaderLocation($uri) { if (PMA_IS_IIS && strlen($uri) > 600) { echo '<html><head><title>- - -</title>' . "\n"; echo '<meta http-equiv="expires" content="0">' . "\n"; echo '<meta http-equiv="Pragma" content="no-cache">' . "\n"; echo '<meta http-equiv="Cache-Control" content="no-cache">' . "\n"; echo '<meta http-equiv="Refresh" content="0;url=' .$uri . '">' . "\n"; echo '<script type="text/javascript" language="javascript">' . "\n"; echo '//<![CDATA[' . "\n"; echo 'setTimeout ("window.location = unescape(\'"' . $uri . '"\')",2000); </script>' . "\n"; echo '//]]>' . "\n"; echo '</head>' . "\n"; echo '<body>' . "\n"; echo '<script type="text/javascript" language="javascript">' . "\n"; echo '//<![CDATA[' . "\n"; echo 'document.write (\'<p><a href="' . $uri . '">' . $GLOBALS['strGo'] . '</a></p>\');' . "\n"; echo '//]]>' . "\n"; echo '</script></body></html>' . "\n"; } else { if (SID) { if (strpos($uri, '?') === false) { header('Location: ' . $uri . '?' . SID); } else { // use seperators defined by php, but prefer ';' // as recommended by W3C $php_arg_separator_input = ini_get('arg_separator.input'); if (strpos($php_arg_separator_input, ';') !== false) { $separator = ';'; } elseif (strlen($php_arg_separator_input) > 0) { $separator = $php_arg_separator_input{0}; } else { $separator = '&'; } header('Location: ' . $uri . $separator . SID); } } else { session_write_close(); // bug #1523784, IE6 does not like 'Refresh: 0', it // results in a blank page //if (PMA_IS_IIS) { // header('Refresh: 0; ' . $uri); //} else { header('Location: ' . $uri); //} } } } /** * Get the list and number of available databases. * * @param string the url to go back to in case of error * * @return boolean always true * * @global array the list of available databases * @global integer the number of available databases * @global array current configuration */ function PMA_availableDatabases($error_url = '') { global $dblist; global $num_dbs; global $cfg; // 1. A list of allowed databases has already been defined by the // authentication process -> gets the available databases list if (count($dblist)) { foreach ($dblist as $key => $db) { if (!@PMA_DBI_select_db($db) || (!empty($GLOBALS['cfg']['Server']['hide_db']) && preg_match('/' . $GLOBALS['cfg']['Server']['hide_db'] . '/', $db))) { unset($dblist[$key]); } // end if } // end for } // end if // 2. Allowed database list is empty -> gets the list of all databases // on the server elseif (empty($cfg['Server']['only_db'])) { $dblist = PMA_DBI_get_dblist(); // needed? or PMA_mysqlDie('', 'SHOW DATABASES;', false, $error_url); } // end else $num_dbs = count($dblist); // natural order for db list; but do not sort if user asked // for a specific order with the 'only_db' mechanism if (!is_array($GLOBALS['cfg']['Server']['only_db']) && $GLOBALS['cfg']['NaturalOrder']) { natsort($dblist); } return true; } // end of the 'PMA_availableDatabases()' function /** * returns array with tables of given db with extended infomation and grouped * * @uses $GLOBALS['cfg']['LeftFrameTableSeparator'] * @uses $GLOBALS['cfg']['LeftFrameTableLevel'] * @uses $GLOBALS['cfg']['ShowTooltipAliasTB'] * @uses $GLOBALS['cfg']['NaturalOrder'] * @uses PMA_DBI_fetch_result() * @uses PMA_backquote() * @uses count() * @uses array_merge * @uses uksort() * @uses strstr() * @uses explode() * @param string $db name of db * return array (rekursive) grouped table list */ function PMA_getTableList($db, $tables = null) { $sep = $GLOBALS['cfg']['LeftFrameTableSeparator']; if ( null === $tables ) { $tables = PMA_DBI_get_tables_full($db); if ($GLOBALS['cfg']['NaturalOrder']) { uksort($tables, 'strnatcasecmp'); } } if (count($tables) < 1) { return $tables; } $default = array( 'Name' => '', 'Rows' => 0, 'Comment' => '', 'disp_name' => '', ); $table_groups = array(); foreach ($tables as $table_name => $table) { // check for correct row count if (null === $table['Rows']) { // Do not check exact row count here, // if row count is invalid possibly the table is defect // and this would break left frame; // but we can check row count if this is a view, // since PMA_countRecords() returns a limited row count // in this case. // set this because PMA_countRecords() can use it $tbl_is_view = PMA_tableIsView($db, $table['Name']); if ($tbl_is_view) { $table['Rows'] = PMA_countRecords($db, $table['Name'], $return = true); } } // in $group we save the reference to the place in $table_groups // where to store the table info if ($GLOBALS['cfg']['LeftFrameDBTree'] && $sep && strstr($table_name, $sep)) { $parts = explode($sep, $table_name); $group =& $table_groups; $i = 0; $group_name_full = ''; while ($i < count($parts) - 1 && $i < $GLOBALS['cfg']['LeftFrameTableLevel']) { $group_name = $parts[$i] . $sep; $group_name_full .= $group_name; if (!isset($group[$group_name])) { $group[$group_name] = array(); $group[$group_name]['is' . $sep . 'group'] = true; $group[$group_name]['tab' . $sep . 'count'] = 1; $group[$group_name]['tab' . $sep . 'group'] = $group_name_full; } elseif (!isset($group[$group_name]['is' . $sep . 'group'])) { $table = $group[$group_name]; $group[$group_name] = array(); $group[$group_name][$group_name] = $table; unset($table); $group[$group_name]['is' . $sep . 'group'] = true; $group[$group_name]['tab' . $sep . 'count'] = 1; $group[$group_name]['tab' . $sep . 'group'] = $group_name_full; } else { $group[$group_name]['tab' . $sep . 'count']++; } $group =& $group[$group_name]; $i++; } } else { if (!isset($table_groups[$table_name])) { $table_groups[$table_name] = array(); } $group =& $table_groups; } if ($GLOBALS['cfg']['ShowTooltipAliasTB'] && $GLOBALS['cfg']['ShowTooltipAliasTB'] !== 'nested') { // switch tooltip and name $table['Comment'] = $table['Name']; $table['disp_name'] = $table['Comment']; } else { $table['disp_name'] = $table['Name']; } $group[$table_name] = array_merge($default, $table); } return $table_groups; } /* ----------------------- Set of misc functions ----------------------- */ /** * Adds backquotes on both sides of a database, table or field name. * and escapes backquotes inside the name with another backquote * * <code> * echo PMA_backquote('owner`s db'); // `owner``s db` * </code> * * @param mixed $a_name the database, table or field name to "backquote" * or array of it * @param boolean $do_it 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) { return $a_name; } if (is_array($a_name)) { $result = array(); foreach ($a_name as $key => $val) { $result[$key] = PMA_backquote($val); } return $result; } // '0' is also empty for php :-( if (strlen($a_name) && $a_name != '*') { return '`' . str_replace('`', '``', $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 elseif (PMA_USR_OS == 'Mac') { $the_crlf = "\r"; } // Others else { $the_crlf = "\n"; } return $the_crlf; } // end of the 'PMA_whichCrlf()' function /** * Checks if this "table" is a view * * @param string the database name * @param string the table name * * @return boolean whether this is a view * * @access public */ function PMA_tableIsView($db, $table) { // maybe we already know if the table is a view // TODO: see what we could do with the possible existence // of $table_is_view if (isset($GLOBALS['tbl_is_view']) && $GLOBALS['tbl_is_view']) { return true; } // old MySQL version: no view if (PMA_MYSQL_INT_VERSION < 50000) { return false; } if ( false === PMA_DBI_fetch_value('SELECT TABLE_NAME FROM information_schema.VIEWS WHERE TABLE_SCHEMA = \'' . $db . '\' AND TABLE_NAME = \'' . $table . '\';')) { return false; } else { return true; } } /** * Counts and returns (or displays) the number of records in a table * * Revision 13 July 2001: Patch for limiting dump size from * vinay@sanisoft.com & girish@sanisoft.com
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -