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
9 if (! defined('PHPMYADMIN')) {
16 if (isset($plugin_list)) {
17 $plugin_list['yaml'] = array(
20 'mime_type' => 'text/yaml',
23 array('type' => 'begin_group', 'name' => 'general_opts'),
26 'name' => 'structure_or_data',
28 array('type' => 'end_group')
30 'options_text' => __('Options'),
35 * Set of functions used to build exports of tables
39 * Outputs export footer
41 * @return bool Whether it suceeded
45 function PMA_exportFooter()
47 PMA_exportOutputHandler('...' . $GLOBALS['crlf']);
52 * Outputs export header
54 * @return bool Whether it suceeded
58 function PMA_exportHeader()
60 PMA_exportOutputHandler('%YAML 1.1' . $GLOBALS['crlf'] . '---' . $GLOBALS['crlf']);
65 * Outputs database header
67 * @param string $db Database name
68 * @return bool Whether it suceeded
72 function PMA_exportDBHeader($db)
78 * Outputs database footer
80 * @param string $db Database name
81 * @return bool Whether it suceeded
85 function PMA_exportDBFooter($db)
91 * Outputs CREATE DATABASE statement
93 * @param string $db Database name
94 * @return bool Whether it suceeded
98 function PMA_exportDBCreate($db)
104 * Outputs the content of a table in YAML format
106 * @param string $db database name
107 * @param string $table table name
108 * @param string $crlf the end of line sequence
109 * @param string $error_url the url to go back in case of error
110 * @param string $sql_query SQL query for obtaining data
111 * @return bool Whether it suceeded
115 function PMA_exportData($db, $table, $crlf, $error_url, $sql_query)
117 $result = PMA_DBI_query($sql_query, null, PMA_DBI_QUERY_UNBUFFERED
);
119 $columns_cnt = PMA_DBI_num_fields($result);
120 for ($i = 0; $i < $columns_cnt; $i++
) {
121 $columns[$i] = stripslashes(PMA_DBI_field_name($result, $i));
127 while ($record = PMA_DBI_fetch_row($result)) {
130 // Output table name as comment if this is the first record of the table
131 if ($record_cnt == 1) {
132 $buffer = '# ' . $db . '.' . $table . $crlf;
133 $buffer .= '-' . $crlf;
135 $buffer = '-' . $crlf;
138 for ($i = 0; $i < $columns_cnt; $i++
) {
139 if (! isset($record[$i])) {
143 $column = $columns[$i];
145 if (is_null($record[$i])) {
146 $buffer .= ' ' . $column . ': null' . $crlf;
150 if (is_numeric($record[$i])) {
151 $buffer .= ' ' . $column . ': ' . $record[$i] . $crlf;
155 $record[$i] = str_replace(array('\\', '"', "\n", "\r"), array('\\\\', '\"', '\n', '\r'), $record[$i]);
156 $buffer .= ' ' . $column . ': "' . $record[$i] . '"' . $crlf;
159 if (! PMA_exportOutputHandler($buffer)) {
163 PMA_DBI_free_result($result);