PMA\libraries\plugins\export\ExportXml::exportData PHP Method

exportData() public method

Outputs the content of a table in XML format
public exportData ( string $db, string $table, string $crlf, string $error_url, string $sql_query, array $aliases = [] ) : boolean
$db string database name
$table string table name
$crlf string the end of line sequence
$error_url string the url to go back in case of error
$sql_query string SQL query for obtaining data
$aliases array Aliases of db/table/columns
return boolean Whether it succeeded
    public function exportData($db, $table, $crlf, $error_url, $sql_query, $aliases = array())
    {
        // Do not export data for merge tables
        if ($GLOBALS['dbi']->getTable($db, $table)->isMerge()) {
            return true;
        }
        $db_alias = $db;
        $table_alias = $table;
        $this->initAlias($aliases, $db_alias, $table_alias);
        if (isset($GLOBALS['xml_export_contents']) && $GLOBALS['xml_export_contents']) {
            $result = $GLOBALS['dbi']->query($sql_query, null, DatabaseInterface::QUERY_UNBUFFERED);
            $columns_cnt = $GLOBALS['dbi']->numFields($result);
            $columns = array();
            for ($i = 0; $i < $columns_cnt; $i++) {
                $columns[$i] = stripslashes($GLOBALS['dbi']->fieldName($result, $i));
            }
            unset($i);
            $buffer = '        <!-- ' . __('Table') . ' ' . htmlspecialchars($table_alias) . ' -->' . $crlf;
            if (!PMA_exportOutputHandler($buffer)) {
                return false;
            }
            while ($record = $GLOBALS['dbi']->fetchRow($result)) {
                $buffer = '        <table name="' . htmlspecialchars($table_alias) . '">' . $crlf;
                for ($i = 0; $i < $columns_cnt; $i++) {
                    $col_as = $columns[$i];
                    if (!empty($aliases[$db]['tables'][$table]['columns'][$col_as])) {
                        $col_as = $aliases[$db]['tables'][$table]['columns'][$col_as];
                    }
                    // If a cell is NULL, still export it to preserve
                    // the XML structure
                    if (!isset($record[$i]) || is_null($record[$i])) {
                        $record[$i] = 'NULL';
                    }
                    $buffer .= '            <column name="' . htmlspecialchars($col_as) . '">' . htmlspecialchars((string) $record[$i]) . '</column>' . $crlf;
                }
                $buffer .= '        </table>' . $crlf;
                if (!PMA_exportOutputHandler($buffer)) {
                    return false;
                }
            }
            $GLOBALS['dbi']->freeResult($result);
        }
        return true;
    }