⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 common.lib.php

📁 一个用PHP编写的
💻 PHP
📖 第 1 页 / 共 5 页
字号:
     *     * @param   string   the current database name     * @param   string   the current table name     * @param   boolean  whether to retain or to displays the result     * @param   boolean  whether to force an exact count     *     * @return  mixed    the number of records if retain is required, true else     *     * @access  public     */    function PMA_countRecords($db, $table, $ret = false, $force_exact = false)    {        global $err_url, $cfg;        if (!$force_exact) {            $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);        }        $tbl_is_view = PMA_tableIsView($db, $table);        if (!isset($num)) {            if (! $tbl_is_view) {                $num = PMA_DBI_fetch_value('SELECT COUNT(*) AS num FROM ' . PMA_backquote($db) . '.' . PMA_backquote($table));                // necessary?                if (! $num) {                    $num = 0;                }            // since counting all rows of a view could be too long            } else {                // try_query because if can fail (a VIEW was based on a                // table that no longer exists)                $result = PMA_DBI_try_query('SELECT 1 FROM ' . PMA_backquote($db) . '.' . PMA_backquote($table) . ' LIMIT ' . $cfg['MaxExactCount'], null, PMA_DBI_QUERY_STORE);                if (!PMA_DBI_getError()) {                    $num = PMA_DBI_num_rows($result);                } else {                    $num = 0;                }            }        }        if ($ret) {            return $num;        } else {            // Note: as of PMA 2.8.0, we no longer seem to be using            // PMA_countRecords() in display mode.            echo number_format($num, 0, $GLOBALS['number_decimal_separator'], $GLOBALS['number_thousands_separator']);            if ($tbl_is_view) {                echo '&nbsp;' . sprintf($GLOBALS['strViewMaxExactCount'], $cfg['MaxExactCount'], '[a@./Documentation.html#cfg_MaxExactCount@_blank]', '[/a]');            }            return true;        }    } // end of the 'PMA_countRecords()' function    /**     * Reloads navigation if needed.     *     * @global  mixed   configuration     * @global  bool    whether to reload     *     * @access  public     */    function PMA_reloadNavigation()    {        global $cfg;        // 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="javascript">//<![CDATA[if (typeof(window.parent) != 'undefined'    && typeof(window.parent.frames[0]) != 'undefined') {    window.parent.goTo('<?php echo $reload_url; ?>');}//]]></script>            <?php            unset($GLOBALS['reload']);        }    }    /**     * 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);        // Corrects the tooltip text via JS if required        if ( isset($GLOBALS['table']) && strlen($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 .= '(' . PMA_formatNumber($tbl_status['Rows'], 0) . ' ' . $GLOBALS['strRows'] . ')';                PMA_DBI_free_result($result);                $uni_tbl = PMA_jsFormat($GLOBALS['db'] . '.' . $GLOBALS['table'], false);                echo "\n";                ?><script type="text/javascript" language="javascript">//<![CDATA[window.parent.updateTableTitle('<?php echo $uni_tbl; ?>', '<?php echo PMA_jsFormat($tooltip, false); ?>');//]]></script>                <?php            } // end if        } // end if ... elseif        // 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);        ?><br /><div align="<?php echo $GLOBALS['cell_align_left']; ?>">        <?php        if (!empty($GLOBALS['show_error_header'])) {            ?>    <div class="error">        <h1><?php echo $GLOBALS['strError']; ?></h1>            <?php        }        echo $message;        if (isset($GLOBALS['special_message'])) {            echo PMA_sanitize($GLOBALS['special_message']);            unset($GLOBALS['special_message']);        }        if (!empty($GLOBALS['show_error_header'])) {            echo '</div>';        }        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'] : '');            // 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 */            if (!empty($GLOBALS['show_as_php'])) {                $new_line = '\'<br />' . "\n" . '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;. \' ';            }            if (isset($new_line)) {                 /* SQL-Parser-Analyzer */                $query_base = PMA_sqlAddslashes(htmlspecialchars($local_query), false, false, true);                 /* SQL-Parser-Analyzer */                $query_base = preg_replace("@((\015\012)|(\015)|(\012))+@", $new_line, $query_base);            } else {                $query_base = $local_query;            }            // Parse SQL if needed            if (isset($GLOBALS['parsed_sql']) && $query_base == $GLOBALS['parsed_sql']['raw']) {                $parsed_sql = $GLOBALS['parsed_sql'];            } else {                // when the query is large (for example an INSERT of binary                // data), the parser chokes; so avoid parsing it                if (strlen($query_base) < 1000) {                    $parsed_sql = PMA_SQP_parse($query_base);                }            }            // Analyze it            if (isset($parsed_sql)) {                $analyzed_display_query = PMA_SQP_analyze($parsed_sql);            }            // 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 ?            if (isset($analyzed_display_query[0]['queryflags']['select_from'])             && isset($GLOBALS['sql_limit_to_append'])) {                $query_base  = $analyzed_display_query[0]['section_before_limit'] . "\n" . $GLOBALS['sql_limit_to_append'] . $analyzed_display_query[0]['section_after_limit'];                // Need to reparse query                $parsed_sql = PMA_SQP_parse($query_base);            }            if (!empty($GLOBALS['show_as_php'])) {                $query_base = '$sql  = \'' . $query_base;            } elseif (!empty($GLOBALS['validatequery'])) {                $query_base = PMA_validateSQL($query_base);            } else {                if (isset($parsed_sql)) {                    $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)            // (also, I don't see why we should check the goto variable)            //if (!isset($GLOBALS['goto'])) {                //$edit_target = (isset($GLOBALS['table'])) ? $cfg['DefaultTabTable'] : $cfg['DefaultTabDatabase'];            $edit_target = isset($GLOBALS['db']) ? (isset($GLOBALS['table']) ? 'tbl_properties.php' : 'db_details.php') : 'server_sql.php';            //} elseif ($GLOBALS['goto'] != 'main.php') {            //    $edit_target = $GLOBALS['goto'];            //} else {            //    $edit_target = '';            //}            if (isset($cfg['SQLQuery']['Edit'])                && ($cfg['SQLQuery']['Edit'] == true)                && (!empty($edit_target))) {                if ($cfg['EditInWindow'] == true) {                    $onclick = 'window.parent.focus_querywindow(\'' . urlencode($local_query) . '\'); return false;';                } else {                    $onclick = '';                }                $edit_link = $edit_target                           . $url_qpart                           . '&amp;sql_query=' . urlencode($local_query)                           . '&amp;show_query=1#querybox';                $edit_link = ' [' . PMA_linkOrButton($edit_link, $GLOBALS['strEdit'], array('onclick' => $onclick)) . ']';            } else {                $edit_link = '';            }            // Want to have the query explained (Mike Beck 2002-05-22)            // but only explain a SELECT (that has not been explained)            /* SQL-Parser-Analyzer */            if (isset($cfg['SQLQuery']['Explain'])                && $cfg['SQLQuery']['Explain'] == true) {                // Detect if we are validating as well                // To preserve the validate uRL data                if (!empty($GLOBALS['validatequery'])) {                    $explain_link_validate = '&amp;validatequery=1';                } else {                    $explain_link_validate = '';                }                $explain_link = 'import.php'                              . $url_qpart                              . $explain_link_validate                              . '&amp;sql_query=';                if (preg_match('@^SELECT[[:space:]]+@i', $local_query)) {                    $explain_link .= urlencode('EXPLAIN ' . $local_query);                    $message = $GLOBALS['strExplain'];                } elseif (preg_match('@^EXPLAIN[[:space:]]+SELECT[[:space:]]+@i', $local_query)) {                    $explain_link .= urlencode(substr($local_query, 8));                    $message = $GLOBALS['strNoExplain'];                } else {                    $explain_link = '';                }                if (!empty($explain_link)) {                    $explain_link = ' [' . PMA_linkOrButton($explain_link, $message) . ']';                }            } else {                $explain_link = '';            } //show explain            // Also we would like to get the SQL formed in some nice            // php-code (Mike Beck 2002-05-22)            if (isset($cfg['SQLQuery']['ShowAsPHP'])                && $cfg['SQLQuery']['ShowAsPHP'] == true) {                $php_link = 'import.php'                          . $url_qpart                          . '&amp;show_query=1'                          . '&amp;sql_query=' . urlencode($local_query)                          . '&amp;show_as_php=';                if (!empty($GLOBALS['show_as_php'])) {                    $php_link .= '0';                    $message = $GLOBALS['strNoPhp'];                } else {                    $php_link .= '1';                    $message = $GLOBALS['strPhp'];                }                $php_link = ' [' . PMA_linkOrButton($php_link, $message) . ']';                if (isset($GLOBALS['show_as_php']) && $GLOBALS['show_as_php'] == '1') {                    $runquery_link                         = 'import.php'                         . $url_qpart                         . '&amp;show_query=1'                         . '&amp;sql_query=' . urlencode($local_query);                    $php_link .= ' [' . PMA_linkOrButton($runquery_link, $GLOBALS['strRunQuery']) . ']';                }            } else {                $php_link = '';            } //show as php            // Refresh query            if (isset($cfg['SQLQuery']['Refresh'])                && $cfg['SQLQuery']['Refresh']                && preg_match('@^(SELECT|SHOW)[[:space:]]+@i', $local_query)) {                $refresh_link = 'import.php'                          . $url_qpart                          . '&amp;show_query=1'                          . (isset($_GET['pos']) ? '&amp;pos=' . $_GET['pos'] : '')                          . '&amp;sql_query=' . urlencode($local_query);                $refresh_link = ' [' . PMA_linkOrButton($refresh_link, $GLOBALS['strRefresh']) . ']';            } else {                $refresh_link = '';            } //show as php            if (isset($cfg['SQLValidator

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -