2 /* vim: set expandtab sw=4 ts=4 sts=4: */
4 * Set of functions used to build YAML dumps of tables
8 if (! defined('PHPMYADMIN')) {
15 if (isset($plugin_list)) {
16 $plugin_list['yaml'] = array(
19 'mime_type' => 'text/yaml',
27 'options_text' => 'strOptions',
32 * Set of functions used to build exports of tables
38 * @param string Text of comment
40 * @return bool Whether it suceeded
42 function PMA_exportComment($text)
44 PMA_exportOutputHandler('# ' . $text . $GLOBALS['crlf']);
49 * Outputs export footer
51 * @return bool Whether it suceeded
55 function PMA_exportFooter()
57 PMA_exportOutputHandler('...' . $GLOBALS['crlf']);
62 * Outputs export header
64 * @return bool Whether it suceeded
68 function PMA_exportHeader()
70 PMA_exportOutputHandler('%YAML 1.1' . $GLOBALS['crlf'] . '---' . $GLOBALS['crlf']);
75 * Outputs database header
77 * @param string Database name
79 * @return bool Whether it suceeded
83 function PMA_exportDBHeader($db)
89 * Outputs database footer
91 * @param string Database name
93 * @return bool Whether it suceeded
97 function PMA_exportDBFooter($db)
103 * Outputs create database database
105 * @param string Database name
107 * @return bool Whether it suceeded
111 function PMA_exportDBCreate($db)
117 * Outputs the content of a table in YAML format
119 * @param string the database name
120 * @param string the table name
121 * @param string the end of line sequence
122 * @param string the url to go back in case of error
123 * @param string SQL query for obtaining data
125 * @return bool Whether it suceeded
129 function PMA_exportData($db, $table, $crlf, $error_url, $sql_query)
131 $result = PMA_DBI_query($sql_query, null, PMA_DBI_QUERY_UNBUFFERED
);
133 $columns_cnt = PMA_DBI_num_fields($result);
134 for ($i = 0; $i < $columns_cnt; $i++
) {
135 $columns[$i] = stripslashes(PMA_DBI_field_name($result, $i));
140 while ($record = PMA_DBI_fetch_row($result)) {
141 $buffer = '-' . $crlf;
142 for ($i = 0; $i < $columns_cnt; $i++
) {
143 if (! isset($record[$i])) {
147 $column = $columns[$i];
149 if (is_null($record[$i])) {
150 $buffer .= ' ' . $column . ': null' . $crlf;
154 if (is_numeric($record[$i])) {
155 $buffer .= ' ' . $column . ': ' . $record[$i] . $crlf;
159 $record[$i] = preg_replace('/\r\n|\r|\n/', $crlf.' ', $record[$i]);
160 if (strstr($record[$i], $crlf))
161 $record[$i] = '|-' . $crlf . ' '.$record[$i];
163 $buffer .= ' ' . $column . ': ' . $record[$i] . $crlf;
166 if (!PMA_exportOutputHandler($buffer)) {
170 PMA_DBI_free_result($result);