2 /* vim: set expandtab sw=4 ts=4 sts=4: */
4 * Set of functions used to build YAML dumps of tables
6 * @package phpMyAdmin-Export-YAML
8 if (! defined('PHPMYADMIN')) {
15 if (isset($plugin_list)) {
16 $plugin_list['yaml'] = array(
19 'mime_type' => 'text/yaml',
22 array('type' => 'begin_group', 'name' => 'general_opts'),
25 'name' => 'structure_or_data',
27 array('type' => 'end_group')
29 'options_text' => __('Options'),
34 * Set of functions used to build exports of tables
40 * @param string Text of comment
42 * @return bool Whether it suceeded
44 function PMA_exportComment($text)
46 PMA_exportOutputHandler('# ' . $text . $GLOBALS['crlf']);
51 * Outputs export footer
53 * @return bool Whether it suceeded
57 function PMA_exportFooter()
59 PMA_exportOutputHandler('...' . $GLOBALS['crlf']);
64 * Outputs export header
66 * @return bool Whether it suceeded
70 function PMA_exportHeader()
72 PMA_exportOutputHandler('%YAML 1.1' . $GLOBALS['crlf'] . '---' . $GLOBALS['crlf']);
77 * Outputs database header
79 * @param string Database name
81 * @return bool Whether it suceeded
85 function PMA_exportDBHeader($db)
91 * Outputs database footer
93 * @param string Database name
95 * @return bool Whether it suceeded
99 function PMA_exportDBFooter($db)
105 * Outputs create database database
107 * @param string Database name
109 * @return bool Whether it suceeded
113 function PMA_exportDBCreate($db)
119 * Outputs the content of a table in YAML format
121 * @param string the database name
122 * @param string the table name
123 * @param string the end of line sequence
124 * @param string the url to go back in case of error
125 * @param string SQL query for obtaining data
127 * @return bool Whether it suceeded
131 function PMA_exportData($db, $table, $crlf, $error_url, $sql_query)
133 $result = PMA_DBI_query($sql_query, null, PMA_DBI_QUERY_UNBUFFERED
);
135 $columns_cnt = PMA_DBI_num_fields($result);
136 for ($i = 0; $i < $columns_cnt; $i++
) {
137 $columns[$i] = stripslashes(PMA_DBI_field_name($result, $i));
143 while ($record = PMA_DBI_fetch_row($result)) {
146 // Output table name as comment if this is the first record of the table
147 if ($record_cnt == 1) {
148 $buffer = '# ' . $db . '.' . $table . $crlf;
149 $buffer .= '-' . $crlf;
151 $buffer = '-' . $crlf;
154 for ($i = 0; $i < $columns_cnt; $i++
) {
155 if (! isset($record[$i])) {
159 $column = $columns[$i];
161 if (is_null($record[$i])) {
162 $buffer .= ' ' . $column . ': null' . $crlf;
166 if (is_numeric($record[$i])) {
167 $buffer .= ' ' . $column . ': ' . $record[$i] . $crlf;
171 $record[$i] = str_replace(array('\\', '"', "\n", "\r"), array('\\\\', '\"', '\n', '\r'), $record[$i]);
172 $buffer .= ' ' . $column . ': "' . $record[$i] . '"' . $crlf;
175 if (! PMA_exportOutputHandler($buffer)) {
179 PMA_DBI_free_result($result);