Fixed: Not selecting a datalabel used to issue a notice(undefined offset)
[phpmyadmin/ammaryasirr.git] / libraries / export / yaml.php
blob0ec1551208948cd7db98871d375f5f2f3d9fc83b
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 /**
4 * Set of functions used to build YAML dumps of tables
6 * @package phpMyAdmin-Export
7 * @subpackage YAML
8 */
9 if (! defined('PHPMYADMIN')) {
10 exit;
13 /**
16 if (isset($plugin_list)) {
17 $plugin_list['yaml'] = array(
18 'text' => 'YAML',
19 'extension' => 'yml',
20 'mime_type' => 'text/yaml',
21 'force_file' => true,
22 'options' => array(
23 array('type' => 'begin_group', 'name' => 'general_opts'),
24 array(
25 'type' => 'hidden',
26 'name' => 'structure_or_data',
28 array('type' => 'end_group')
30 'options_text' => __('Options'),
32 } else {
34 /**
35 * Set of functions used to build exports of tables
38 /**
39 * Outputs export footer
41 * @return bool Whether it suceeded
43 * @access public
45 function PMA_exportFooter()
47 PMA_exportOutputHandler('...' . $GLOBALS['crlf']);
48 return true;
51 /**
52 * Outputs export header
54 * @return bool Whether it suceeded
56 * @access public
58 function PMA_exportHeader()
60 PMA_exportOutputHandler('%YAML 1.1' . $GLOBALS['crlf'] . '---' . $GLOBALS['crlf']);
61 return true;
64 /**
65 * Outputs database header
67 * @param string $db Database name
68 * @return bool Whether it suceeded
70 * @access public
72 function PMA_exportDBHeader($db)
74 return true;
77 /**
78 * Outputs database footer
80 * @param string $db Database name
81 * @return bool Whether it suceeded
83 * @access public
85 function PMA_exportDBFooter($db)
87 return true;
90 /**
91 * Outputs CREATE DATABASE statement
93 * @param string $db Database name
94 * @return bool Whether it suceeded
96 * @access public
98 function PMA_exportDBCreate($db)
100 return true;
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
113 * @access public
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));
123 unset($i);
125 $buffer = '';
126 $record_cnt = 0;
127 while ($record = PMA_DBI_fetch_row($result)) {
128 $record_cnt++;
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;
134 } else {
135 $buffer = '-' . $crlf;
138 for ($i = 0; $i < $columns_cnt; $i++) {
139 if (! isset($record[$i])) {
140 continue;
143 $column = $columns[$i];
145 if (is_null($record[$i])) {
146 $buffer .= ' ' . $column . ': null' . $crlf;
147 continue;
150 if (is_numeric($record[$i])) {
151 $buffer .= ' ' . $column . ': ' . $record[$i] . $crlf;
152 continue;
155 $record[$i] = str_replace(array('\\', '"', "\n", "\r"), array('\\\\', '\"', '\n', '\r'), $record[$i]);
156 $buffer .= ' ' . $column . ': "' . $record[$i] . '"' . $crlf;
159 if (! PMA_exportOutputHandler($buffer)) {
160 return false;
163 PMA_DBI_free_result($result);
165 return true;