PMA\libraries\Util::getTablesWhenOpen PHP Method

getTablesWhenOpen() public static method

Gets the list of tables in the current db, taking into account that they might be "in use"
public static getTablesWhenOpen ( string $db, object $db_info_result ) : array
$db string database name
$db_info_result object result set
return array $tables list of tables
    public static function getTablesWhenOpen($db, $db_info_result)
    {
        $sot_cache = $tables = array();
        while ($tmp = $GLOBALS['dbi']->fetchAssoc($db_info_result)) {
            $sot_cache[$tmp['Table']] = true;
        }
        $GLOBALS['dbi']->freeResult($db_info_result);
        // is there at least one "in use" table?
        if (isset($sot_cache)) {
            $tblGroupSql = "";
            $whereAdded = false;
            if (PMA_isValid($_REQUEST['tbl_group'])) {
                $group = Util::escapeMysqlWildcards($_REQUEST['tbl_group']);
                $groupWithSeparator = Util::escapeMysqlWildcards($_REQUEST['tbl_group'] . $GLOBALS['cfg']['NavigationTreeTableSeparator']);
                $tblGroupSql .= " WHERE (" . Util::backquote('Tables_in_' . $db) . " LIKE '" . $groupWithSeparator . "%'" . " OR " . Util::backquote('Tables_in_' . $db) . " LIKE '" . $group . "')";
                $whereAdded = true;
            }
            if (PMA_isValid($_REQUEST['tbl_type'], array('table', 'view'))) {
                $tblGroupSql .= $whereAdded ? " AND" : " WHERE";
                if ($_REQUEST['tbl_type'] == 'view') {
                    $tblGroupSql .= " `Table_type` != 'BASE TABLE'";
                } else {
                    $tblGroupSql .= " `Table_type` = 'BASE TABLE'";
                }
            }
            $db_info_result = $GLOBALS['dbi']->query('SHOW FULL TABLES FROM ' . Util::backquote($db) . $tblGroupSql, null, DatabaseInterface::QUERY_STORE);
            unset($tblGroupSql, $whereAdded);
            if ($db_info_result && $GLOBALS['dbi']->numRows($db_info_result) > 0) {
                $names = array();
                while ($tmp = $GLOBALS['dbi']->fetchRow($db_info_result)) {
                    if (!isset($sot_cache[$tmp[0]])) {
                        $names[] = $tmp[0];
                    } else {
                        // table in use
                        $tables[$tmp[0]] = array('TABLE_NAME' => $tmp[0], 'ENGINE' => '', 'TABLE_TYPE' => '', 'TABLE_ROWS' => 0, 'TABLE_COMMENT' => '');
                    }
                }
                // end while
                if (count($names) > 0) {
                    $tables = array_merge($tables, $GLOBALS['dbi']->getTablesFull($db, $names));
                }
                if ($GLOBALS['cfg']['NaturalOrder']) {
                    uksort($tables, 'strnatcasecmp');
                }
            } elseif ($db_info_result) {
                $GLOBALS['dbi']->freeResult($db_info_result);
            }
            unset($sot_cache);
        }
        return $tables;
    }
Util