2 /* vim: set expandtab sw=4 ts=4 sts=4: */
4 * Set of functions used to build XML dumps of tables
8 if (! defined('PHPMYADMIN')) {
15 if (strlen($GLOBALS['db'])) { /* Can't do server export */
17 if (isset($plugin_list)) {
18 $plugin_list['xml'] = array(
21 'mime_type' => 'text/xml',
23 array('type' => 'hidden', 'name' => 'data'),
25 'options_text' => 'strOptions',
32 * @param string Text of comment
34 * @return bool Whether it suceeded
36 function PMA_exportComment($text) {
37 return PMA_exportOutputHandler('<!-- ' . $text . ' -->' . $GLOBALS['crlf']);
41 * Outputs export footer
43 * @return bool Whether it suceeded
47 function PMA_exportFooter() {
52 * Outputs export header
54 * @return bool Whether it suceeded
58 function PMA_exportHeader() {
62 if ($GLOBALS['output_charset_conversion']) {
63 $charset = $GLOBALS['charset_of_file'];
65 $charset = $GLOBALS['charset'];
68 $head = '<?xml version="1.0" encoding="' . $charset . '" ?>' . $crlf
71 . '- phpMyAdmin XML Dump' . $crlf
72 . '- version ' . PMA_VERSION
. $crlf
73 . '- http://www.phpmyadmin.net' . $crlf
75 . '- ' . $GLOBALS['strHost'] . ': ' . $cfg['Server']['host'];
76 if (!empty($cfg['Server']['port'])) {
77 $head .= ':' . $cfg['Server']['port'];
80 . '- ' . $GLOBALS['strGenTime'] . ': ' . PMA_localisedDate() . $crlf
81 . '- ' . $GLOBALS['strServerVersion'] . ': ' . substr(PMA_MYSQL_INT_VERSION
, 0, 1) . '.' . (int) substr(PMA_MYSQL_INT_VERSION
, 1, 2) . '.' . (int) substr(PMA_MYSQL_INT_VERSION
, 3) . $crlf
82 . '- ' . $GLOBALS['strPHPVersion'] . ': ' . phpversion() . $crlf
83 . '-->' . $crlf . $crlf;
84 return PMA_exportOutputHandler($head);
88 * Outputs database header
90 * @param string Database name
92 * @return bool Whether it suceeded
96 function PMA_exportDBHeader($db) {
98 $head = '<!--' . $crlf
99 . '- ' . $GLOBALS['strDatabase'] . ': ' . (isset($GLOBALS['use_backquotes']) ?
PMA_backquote($db) : '\'' . $db . '\''). $crlf
101 . '<' . $db . '>' . $crlf;
102 return PMA_exportOutputHandler($head);
106 * Outputs database footer
108 * @param string Database name
110 * @return bool Whether it suceeded
114 function PMA_exportDBFooter($db) {
116 return PMA_exportOutputHandler('</' . $db . '>' . $crlf);
120 * Outputs create database database
122 * @param string Database name
124 * @return bool Whether it suceeded
128 function PMA_exportDBCreate($db) {
134 * Outputs the content of a table
136 * @param string the database name
137 * @param string the table name
138 * @param string the end of line sequence
139 * @param string the url to go back in case of error
140 * @param string SQL query for obtaining data
142 * @return bool Whether it suceeded
146 function PMA_exportData($db, $table, $crlf, $error_url, $sql_query) {
147 $result = PMA_DBI_query($sql_query, null, PMA_DBI_QUERY_UNBUFFERED
);
149 $columns_cnt = PMA_DBI_num_fields($result);
150 for ($i = 0; $i < $columns_cnt; $i++
) {
151 $columns[$i] = stripslashes(PMA_DBI_field_name($result, $i));
155 $buffer = ' <!-- ' . $GLOBALS['strTable'] . ' ' . $table . ' -->' . $crlf;
156 if (!PMA_exportOutputHandler($buffer)) {
160 while ($record = PMA_DBI_fetch_row($result)) {
161 $buffer = ' <' . $table . '>' . $crlf;
162 for ($i = 0; $i < $columns_cnt; $i++
) {
163 if (isset($record[$i]) && !is_null($record[$i])) {
164 $buffer .= ' <' . $columns[$i] . '>' . htmlspecialchars($record[$i])
165 . '</' . $columns[$i] . '>' . $crlf;
168 $buffer .= ' </' . $table . '>' . $crlf;
170 if (!PMA_exportOutputHandler($buffer)) {
174 PMA_DBI_free_result($result);
177 } // end of the 'PMA_getTableXML()' function