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

📄 db_details_qbe.php

📁 WEBGAME源码,有架设说明,只是非常简单
💻 PHP
📖 第 1 页 / 共 3 页
字号:
    foreach ($Field AS $value) {        $parts             = explode('.', $value);        if (!empty($parts[0]) && !empty($parts[1])) {            $tab_raw       = urldecode($parts[0]);            $tab           = str_replace('`', '', $tab_raw);            $tab_all[$tab] = $tab;            $col_raw       = urldecode($parts[1]);            $col_all[]     = $tab . '.' . str_replace('`', '', $col_raw);         }    } // end while    // Check 'where' clauses    if ($cfgRelation['relwork'] && count($tab_all) > 0) {        // Now we need all tables that we have in the where clause        $crit_cnt         = count($criteria);        for ($x = 0; $x < $crit_cnt; $x++) {            $curr_tab     = explode('.', urldecode($Field[$x]));            if (!empty($curr_tab[0]) && !empty($curr_tab[1])) {                $tab_raw  = urldecode($curr_tab[0]);                $tab      = str_replace('`', '', $tab_raw);                $col_raw  = urldecode($curr_tab[1]);                $col1     = str_replace('`', '', $col_raw);                $col1     = $tab . '.' . $col1;                // Now we know that our array has the same numbers as $criteria                // we can check which of our columns has a where clause                if (!empty($criteria[$x])) {                    if (substr($criteria[$x], 0, 1) == '=' || stristr($criteria[$x], 'is')) {                        $col_where[$col] = $col1;                        $tab_wher[$tab]  = $tab;                    }                } // end if            } // end if        } // end for        // Cleans temp vars w/o further use        unset($tab_raw);        unset($col_raw);        unset($col1);        if (count($tab_wher) == 1) {            // If there is exactly one column that has a decent where-clause            // we will just use this            $master = key($tab_wher);        } else {            // Now let's find out which of the tables has an index            // ( When the control user is the same as the normal user            // because he is using one of his databases as pmadb,            // the last db selected is not always the one where we need to work)            PMA_DBI_select_db($db);            foreach ($tab_all AS $tab) {                $ind_rs   = PMA_DBI_query('SHOW INDEX FROM ' . PMA_backquote($tab) . ';');                while ($ind = PMA_DBI_fetch_assoc($ind_rs)) {                    $col1 = $tab . '.' . $ind['Column_name'];                    if (isset($col_all[$col1])) {                        if ($ind['non_unique'] == 0) {                            if (isset($col_where[$col1])) {                                $col_unique[$col1] = 'Y';                            } else {                                $col_unique[$col1] = 'N';                            }                        } else {                            if (isset($col_where[$col1])) {                                $col_index[$col1] = 'Y';                            } else {                                $col_index[$col1] = 'N';                            }                        }                    }                } // end while (each col of tab)            } // end while (each tab)            // now we want to find the best.            if (isset($col_unique) && count($col_unique) > 0) {                $col_cand = $col_unique;                $needsort = 1;            } elseif (isset($col_index) && count($col_index) > 0) {                $col_cand = $col_index;                $needsort = 1;            } elseif (isset($col_where) && count($col_where) > 0) {                $col_cand = $tab_wher;                $needsort = 0;            } else {                $col_cand = $tab_all;                $needsort = 0;            }            // If we came up with $col_unique (very good) or $col_index (still            // good) as $col_cand we want to check if we have any 'Y' there            // (that would mean that they were also found in the whereclauses            // which would be great). if yes, we take only those            if ($needsort == 1) {                foreach ($col_cand AS $col => $is_where) {                    $tab           = explode('.', $col);                    $tab           = $tab[0];                    if ($is_where == 'Y') {                        $vg[$col]  = $tab;                    } else {                        $sg[$col]  = $tab;                    }                }                if (isset($vg)) {                    $col_cand      = $vg;                    // Candidates restricted in index+where                } else {                    $col_cand      = $sg;                    // None of the candidates where in a where-clause                }            }            // If our array of candidates has more than one member we'll just            // find the smallest table.            // Of course the actual query would be faster if we check for            // the Criteria which gives the smallest result set in its table,            // but it would take too much time to check this            if (count($col_cand) > 1) {                // Of course we only want to check each table once                $checked_tables = $col_cand;                foreach ($col_cand AS $tab) {                    if ($checked_tables[$tab] != 1 ) {                        $tsize[$tab] = PMA_Table::countRecords($db, $tab, true, false);                        $checked_tables[$tab] = 1;                    }                    $csize[$tab] = $tsize[$tab];                }                asort($csize);                reset($csize);                $master = key($csize); // Smallest            } else {                reset($col_cand);                $master = current($col_cand); // Only one single candidate            }        } // end if (exactly one where clause)        /**         * Removes unwanted entries from an array (PHP3 compliant)         *         * @param   array  the array to work with         * @param   array  the list of keys to remove         *         * @return  array  the cleaned up array         *         * @access  private         */        function PMA_arrayShort($array, $key)        {            foreach ($array AS $k => $v) {                if ($k != $key) {                    $reta[$k] = $v;                }            }            if (!isset($reta)) {                $reta = array();            }            return $reta;        } // end of the "PMA_arrayShort()" function        /**         * Finds all related tables         *         * @param   string   wether to go from master to foreign or vice versa         *         * @return  boolean  always TRUE         *         * @global  array    the list of tables that we still couldn't connect         * @global  array    the list of allready connected tables         * @global  string   the current databse name         * @global  string   the super user connection id         * @global  array    the list of relation settings         *         * @access  private         */        function PMA_getRelatives($from) {            global $tab_left, $tab_know, $fromclause;            global $controllink, $db, $cfgRelation;            if ($from == 'master') {                $to    = 'foreign';            } else {                $to    = 'master';            }            $in_know = '(\'' . implode('\', \'', $tab_know) . '\')';            $in_left = '(\'' . implode('\', \'', $tab_left) . '\')';            $rel_query = 'SELECT *'                       . ' FROM ' . PMA_backquote($cfgRelation['relation'])                       . ' WHERE ' . $from . '_db   = \'' . PMA_sqlAddslashes($db) . '\''                       . ' AND ' . $to   . '_db   = \'' . PMA_sqlAddslashes($db) . '\''                       . ' AND ' . $from . '_table IN ' . $in_know                       . ' AND ' . $to   . '_table IN ' . $in_left;            PMA_DBI_select_db($cfgRelation['db'], $controllink);            $relations = @PMA_DBI_query($rel_query, $controllink);            PMA_DBI_select_db($db, $controllink);            while ($row = PMA_DBI_fetch_assoc($relations)) {                $found_table                = $row[$to . '_table'];                if (isset($tab_left[$found_table])) {                    $fromclause             .= "\n" . ' LEFT JOIN '                                            . PMA_backquote($row[$to . '_table']) . ' ON '                                            . PMA_backquote($row[$from . '_table']) . '.'                                            . PMA_backquote($row[$from . '_field']) . ' = '                                            . PMA_backquote($row[$to . '_table']) . '.'                                            . PMA_backquote($row[$to . '_field']) . ' ';                    $tab_know[$found_table] = $found_table;                    $tab_left               = PMA_arrayShort($tab_left, $found_table);                }            } // end while            return TRUE;        } // end of the "PMA_getRelatives()" function        $tab_left          = PMA_arrayShort($tab_all, $master);        $tab_know[$master] = $master;        $run   = 0;        $emerg = '';        while (count($tab_left) > 0) {            if ($run % 2 == 0) {                PMA_getRelatives('master');            } else {                PMA_getRelatives('foreign');            }            $run++;            if ($run > 5) {                foreach ($tab_left AS $tab) {                    $emerg    .= ', ' . PMA_backquote($tab);                    $tab_left = PMA_arrayShort($tab_left, $tab);                }            }        } // end while        $qry_from = PMA_backquote($master) . $emerg . $fromclause;    } // end if ($cfgRelation['relwork'] && count($tab_all) > 0)} // end count($Field) > 0// In case relations are not defined, just generate the FROM clause// from the list of tables, however we don't generate any JOINif (empty($qry_from) && isset($tab_all)) {    $qry_from = implode(', ', $tab_all);}// Now let's see what we gotif (!empty($qry_from)) {    $encoded_qry  .= urlencode('FROM ' . $qry_from . "\n");    echo 'FROM ' . htmlspecialchars($qry_from) . "\n";}// 3. WHERE$qry_where          = '';$criteria_cnt       = 0;for ($x = 0; $x < $col; $x++) {    if (!empty($curField[$x]) && !empty($curCriteria[$x]) && $x && isset($last_where) && isset($curAndOrCol)) {        $qry_where  .= ' ' . strtoupper($curAndOrCol[$last_where]) . ' ';    }    if (!empty($curField[$x]) && !empty($curCriteria[$x])) {        $qry_where  .= '(' . $curField[$x] . ' ' . $curCriteria[$x] . ')';        $last_where = $x;        $criteria_cnt++;    }} // end forif ($criteria_cnt > 1) {    $qry_where      = '(' . $qry_where . ')';}// OR rows ${'cur' . $or}[$x]if (!isset($curAndOrRow)) {    $curAndOrRow          = array();}for ($y = 0; $y <= $row; $y++) {    $criteria_cnt         = 0;    $qry_orwhere          = '';    $last_orwhere         = '';    for ($x = 0; $x < $col; $x++) {        if (!empty($curField[$x]) && !empty(${'curOr' . $y}[$x]) && $x) {            $qry_orwhere  .= ' ' . strtoupper($curAndOrCol[$last_orwhere]) . ' ';        }        if (!empty($curField[$x]) && !empty(${'curOr' . $y}[$x])) {            $qry_orwhere  .= '(' . $curField[$x]                          .  ' '                          .  ${'curOr' . $y}[$x]                          .  ')';            $last_orwhere = $x;            $criteria_cnt++;        }    } // end for    if ($criteria_cnt > 1) {        $qry_orwhere      = '(' . $qry_orwhere . ')';    }    if (!empty($qry_orwhere)) {        $qry_where .= "\n"                   .  strtoupper(isset($curAndOrRow[$y]) ? $curAndOrRow[$y] . ' ' : '')                   .  $qry_orwhere;    } // end if} // end forif (!empty($qry_where) && $qry_where != '()') {    $encoded_qry .= urlencode('WHERE ' . $qry_where . "\n");    echo 'WHERE ' . htmlspecialchars($qry_where) . "\n";} // end if// 4. ORDER BY$last_orderby = 0;if (!isset($qry_orderby)) {    $qry_orderby      = '';}for ($x = 0; $x < $col; $x++) {    if ($last_orderby && $x && !empty($curField[$x]) && !empty($curSort[$x])) {        $qry_orderby  .=  ', ';    }    if (!empty($curField[$x]) && !empty($curSort[$x])) {        // if they have chosen all fields using the * selector,        // then sorting is not available        // Robbat2 - Fix for Bug #570698        if (substr($curField[$x], -2) != '.*') {            $qry_orderby  .=  $curField[$x] . ' ' . $curSort[$x];            $last_orderby = 1;        }    }} // end forif (!empty($qry_orderby)) {    $encoded_qry .= urlencode('ORDER BY ' . $qry_orderby);    echo 'ORDER BY ' . htmlspecialchars($qry_orderby) . "\n";}?>        </textarea>        <input type="hidden" name="encoded_sql_query" value="<?php echo $encoded_qry; ?>" />        </fieldset>        <fieldset class="tblFooters">            <input type="submit" name="submit_sql" value="<?php echo $strRunQuery; ?>" />        </fieldset>    </td></tr></table></form><?php/** * Displays the footer */require_once './libraries/footer.inc.php';?>

⌨️ 快捷键说明

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