/** * mixed XMLData(string $db, string $table, array $options = null) * * Returns the content of a table in XML format (Propel model more or less) * * @param string $db database name * @param string $table table name * @param array $options (optional) (from, to, start_table, end_table) * @return mixed false if error occurs, string if ok * @access public * @static * @see DUMP_CRLF */ public static function XMLData($db, $table, $options = null) { $localConn = new DbConnection(); if (!$localConn->connect()) { return false; } $localQuery = 'SHOW COLUMNS FROM ' . self::backQuote($table) . ' FROM ' . self::backQuote($db); if (!$localConn->exec($localQuery)) { return false; } for ($i = 0; $row = $localConn->fetchRow(MYSQL_ASSOC); $i++) { $fields[$i] = $row['Field']; $types[$i] = $row['Type']; $nulls[$i] = strtoupper($row['Null']) == 'YES' ? 'true' : 'false'; $keys[$i] = $row['Key']; $defaults[$i] = $row['Default']; $extras[$i] = $row['Extra']; } $numFields = count($fields); // Defines the offsets to use $limitClause = isset($options['to']) && $options['to'] > 0 && (isset($options['from']) && $options['from'] >= 0) ? ' LIMIT ' . ($options['from'] > 0 ? $options['from'] . ', ' : '') . $options['to'] : ''; $localQuery = 'SELECT * FROM ' . self::backQuote($db) . '.' . self::backQuote($table) . $limitClause; if (!$localConn->exec($localQuery)) { return false; } if ($localConn->numRows() == 0) { return ''; } $buffer = ' <table name="' . $table . '">' . DUMP_CRLF; while ($record = $localConn->fetchRow(MYSQL_ASSOC)) { $buffer .= ' <row>' . DUMP_CRLF; for ($i = 0; $i < $numFields; $i++) { $element = ' name="' . $fields[$i] . '"' . ' type="' . $types[$i] . '"' . ($nulls[$i] ? ' null="' . $nulls[$i] . '"' : '') . ($keys[$i] ? ' key="' . $keys[$i] . '"' : '') . ($defaults[$i] ? ' default="' . $defaults[$i] . '"' : '') . ($extras[$i] ? ' extra="' . $extras[$i] . '"' : ''); if (!is_null($record[$fields[$i]])) { $buffer .= ' <column' . $element . '>' . htmlspecialchars($record[$fields[$i]]) . '</column>' . DUMP_CRLF; } else { $buffer .= ' <column' . $element . ' />' . DUMP_CRLF; } } $buffer .= ' </row>' . DUMP_CRLF; } $localConn->close(); $buffer .= ' </table>' . DUMP_CRLF; return $buffer; }
} else { header('Content-Disposition: attachment; filename="' . $filename . '.' . $ext . '"'); header('Expires: 0'); header('Pragma: no-cache'); } } // end download /** * Builds the dump */ // Gets the number of tables if a dump of a database has been required if (!isset($_POST['table_select']) || count($_POST['table_select']) != 1) { $auxConn = new DbConnection(); $auxConn->connect(); $result = $auxConn->listTables(); $numTables = $result ? $auxConn->numRows() : 0; $single = false; } else { $numTables = 1; $single = true; } // No table -> error message if ($numTables == 0) { echo '# ' . _("No tables found in database."); } else { // No csv or xml format -> add some comments at the top if ($_POST['what'] != 'csv' && $_POST['what'] != 'excel' && $_POST['what'] != 'xml') { switch ($_POST['what']) { case "data": $auxStr = _("Structure and data"); break;