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

exportData() public method

Outputs the content of a table in NHibernate 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())
    {
        global $what;
        $db_alias = $db;
        $table_alias = $table;
        $this->initAlias($aliases, $db_alias, $table_alias);
        // Gets the data from the database
        $result = $GLOBALS['dbi']->query($sql_query, null, DatabaseInterface::QUERY_UNBUFFERED);
        $fields_cnt = $GLOBALS['dbi']->numFields($result);
        $fields_meta = $GLOBALS['dbi']->getFieldsMeta($result);
        $field_flags = array();
        for ($j = 0; $j < $fields_cnt; $j++) {
            $field_flags[$j] = $GLOBALS['dbi']->fieldFlags($result, $j);
        }
        $GLOBALS['ods_buffer'] .= '<table:table table:name="' . htmlspecialchars($table_alias) . '">';
        // If required, get fields name at the first line
        if (isset($GLOBALS[$what . '_columns'])) {
            $GLOBALS['ods_buffer'] .= '<table:table-row>';
            for ($i = 0; $i < $fields_cnt; $i++) {
                $col_as = $GLOBALS['dbi']->fieldName($result, $i);
                if (!empty($aliases[$db]['tables'][$table]['columns'][$col_as])) {
                    $col_as = $aliases[$db]['tables'][$table]['columns'][$col_as];
                }
                $GLOBALS['ods_buffer'] .= '<table:table-cell office:value-type="string">' . '<text:p>' . htmlspecialchars(stripslashes($col_as)) . '</text:p>' . '</table:table-cell>';
            }
            // end for
            $GLOBALS['ods_buffer'] .= '</table:table-row>';
        }
        // end if
        // Format the data
        while ($row = $GLOBALS['dbi']->fetchRow($result)) {
            $GLOBALS['ods_buffer'] .= '<table:table-row>';
            for ($j = 0; $j < $fields_cnt; $j++) {
                if (!isset($row[$j]) || is_null($row[$j])) {
                    $GLOBALS['ods_buffer'] .= '<table:table-cell office:value-type="string">' . '<text:p>' . htmlspecialchars($GLOBALS[$what . '_null']) . '</text:p>' . '</table:table-cell>';
                } elseif (stristr($field_flags[$j], 'BINARY') && $fields_meta[$j]->blob) {
                    // ignore BLOB
                    $GLOBALS['ods_buffer'] .= '<table:table-cell office:value-type="string">' . '<text:p></text:p>' . '</table:table-cell>';
                } elseif ($fields_meta[$j]->type == "date") {
                    $GLOBALS['ods_buffer'] .= '<table:table-cell office:value-type="date"' . ' office:date-value="' . date("Y-m-d", strtotime($row[$j])) . '" table:style-name="DateCell">' . '<text:p>' . htmlspecialchars($row[$j]) . '</text:p>' . '</table:table-cell>';
                } elseif ($fields_meta[$j]->type == "time") {
                    $GLOBALS['ods_buffer'] .= '<table:table-cell office:value-type="time"' . ' office:time-value="' . date("\\P\\TH\\Hi\\Ms\\S", strtotime($row[$j])) . '" table:style-name="TimeCell">' . '<text:p>' . htmlspecialchars($row[$j]) . '</text:p>' . '</table:table-cell>';
                } elseif ($fields_meta[$j]->type == "datetime") {
                    $GLOBALS['ods_buffer'] .= '<table:table-cell office:value-type="date"' . ' office:date-value="' . date("Y-m-d\\TH:i:s", strtotime($row[$j])) . '" table:style-name="DateTimeCell">' . '<text:p>' . htmlspecialchars($row[$j]) . '</text:p>' . '</table:table-cell>';
                } elseif ($fields_meta[$j]->numeric && $fields_meta[$j]->type != 'timestamp' && !$fields_meta[$j]->blob || $fields_meta[$j]->type == 'real') {
                    $GLOBALS['ods_buffer'] .= '<table:table-cell office:value-type="float"' . ' office:value="' . $row[$j] . '" >' . '<text:p>' . htmlspecialchars($row[$j]) . '</text:p>' . '</table:table-cell>';
                } else {
                    $GLOBALS['ods_buffer'] .= '<table:table-cell office:value-type="string">' . '<text:p>' . htmlspecialchars($row[$j]) . '</text:p>' . '</table:table-cell>';
                }
            }
            // end for
            $GLOBALS['ods_buffer'] .= '</table:table-row>';
        }
        // end while
        $GLOBALS['dbi']->freeResult($result);
        $GLOBALS['ods_buffer'] .= '</table:table>';
        return true;
    }