PMA\libraries\Util::getDbInfo PHP Method

getDbInfo() public static method

Gets the list of tables in the current db and information about these tables if possible
public static getDbInfo ( string $db, string $sub_part ) : array
$db string database name
$sub_part string part of script name
return array
    public static function getDbInfo($db, $sub_part)
    {
        global $cfg;
        /**
         * limits for table list
         */
        if (!isset($_SESSION['tmpval']['table_limit_offset']) || $_SESSION['tmpval']['table_limit_offset_db'] != $db) {
            $_SESSION['tmpval']['table_limit_offset'] = 0;
            $_SESSION['tmpval']['table_limit_offset_db'] = $db;
        }
        if (isset($_REQUEST['pos'])) {
            $_SESSION['tmpval']['table_limit_offset'] = (int) $_REQUEST['pos'];
        }
        $pos = $_SESSION['tmpval']['table_limit_offset'];
        /**
         * whether to display extended stats
         */
        $is_show_stats = $cfg['ShowStats'];
        /**
         * whether selected db is information_schema
         */
        $db_is_system_schema = false;
        if ($GLOBALS['dbi']->isSystemSchema($db)) {
            $is_show_stats = false;
            $db_is_system_schema = true;
        }
        /**
         * information about tables in db
         */
        $tables = array();
        $tooltip_truename = array();
        $tooltip_aliasname = array();
        // Special speedup for newer MySQL Versions (in 4.0 format changed)
        if (true === $cfg['SkipLockedTables']) {
            $db_info_result = $GLOBALS['dbi']->query('SHOW OPEN TABLES FROM ' . Util::backquote($db) . ' WHERE In_use > 0;');
            // Blending out tables in use
            if ($db_info_result && $GLOBALS['dbi']->numRows($db_info_result) > 0) {
                $tables = self::getTablesWhenOpen($db, $db_info_result);
            } elseif ($db_info_result) {
                $GLOBALS['dbi']->freeResult($db_info_result);
            }
        }
        if (empty($tables)) {
            // Set some sorting defaults
            $sort = 'Name';
            $sort_order = 'ASC';
            if (isset($_REQUEST['sort'])) {
                $sortable_name_mappings = array('table' => 'Name', 'records' => 'Rows', 'type' => 'Engine', 'collation' => 'Collation', 'size' => 'Data_length', 'overhead' => 'Data_free', 'creation' => 'Create_time', 'last_update' => 'Update_time', 'last_check' => 'Check_time', 'comment' => 'Comment');
                // Make sure the sort type is implemented
                if (isset($sortable_name_mappings[$_REQUEST['sort']])) {
                    $sort = $sortable_name_mappings[$_REQUEST['sort']];
                    if ($_REQUEST['sort_order'] == 'DESC') {
                        $sort_order = 'DESC';
                    }
                }
            }
            $groupWithSeparator = false;
            $tbl_type = null;
            $limit_offset = 0;
            $limit_count = false;
            $groupTable = array();
            if (!empty($_REQUEST['tbl_group']) || !empty($_REQUEST['tbl_type'])) {
                if (!empty($_REQUEST['tbl_type'])) {
                    // only tables for selected type
                    $tbl_type = $_REQUEST['tbl_type'];
                }
                if (!empty($_REQUEST['tbl_group'])) {
                    // only tables for selected group
                    $tbl_group = $_REQUEST['tbl_group'];
                    // include the table with the exact name of the group if such
                    // exists
                    $groupTable = $GLOBALS['dbi']->getTablesFull($db, $tbl_group, false, null, $limit_offset, $limit_count, $sort, $sort_order, $tbl_type);
                    $groupWithSeparator = $tbl_group . $GLOBALS['cfg']['NavigationTreeTableSeparator'];
                }
            } else {
                // all tables in db
                // - get the total number of tables
                //  (needed for proper working of the MaxTableList feature)
                $tables = $GLOBALS['dbi']->getTables($db);
                $total_num_tables = count($tables);
                if (isset($sub_part) && $sub_part == '_export') {
                    // (don't fetch only a subset if we are coming from
                    // db_export.php, because I think it's too risky to display only
                    // a subset of the table names when exporting a db)
                    /**
                     *
                     * @todo Page selector for table names?
                     */
                } else {
                    // fetch the details for a possible limited subset
                    $limit_offset = $pos;
                    $limit_count = true;
                }
            }
            $tables = array_merge($groupTable, $GLOBALS['dbi']->getTablesFull($db, $groupWithSeparator, $groupWithSeparator !== false, null, $limit_offset, $limit_count, $sort, $sort_order, $tbl_type));
        }
        $num_tables = count($tables);
        //  (needed for proper working of the MaxTableList feature)
        if (!isset($total_num_tables)) {
            $total_num_tables = $num_tables;
        }
        /**
         * If coming from a Show MySQL link on the home page,
         * put something in $sub_part
         */
        if (empty($sub_part)) {
            $sub_part = '_structure';
        }
        return array($tables, $num_tables, $total_num_tables, $sub_part, $is_show_stats, $db_is_system_schema, $tooltip_truename, $tooltip_aliasname, $pos);
    }

Usage Example

コード例 #1
0
 /**
  * Retrieves databse information for further use
  *
  * @param string $sub_part Page part name
  *
  * @return void
  */
 private function _getDbInfo($sub_part)
 {
     list($tables, $num_tables, $total_num_tables, , $is_show_stats, $db_is_system_schema, , , $pos) = Util::getDbInfo($this->db, $sub_part);
     $this->_tables = $tables;
     $this->_num_tables = $num_tables;
     $this->_pos = $pos;
     $this->_db_is_system_schema = $db_is_system_schema;
     $this->_total_num_tables = $total_num_tables;
     $this->_is_show_stats = $is_show_stats;
 }
All Usage Examples Of PMA\libraries\Util::getDbInfo
Util