BLOB streaming documentation
[phpmyadmin/crack.git] / libraries / export / yaml.php
bloba44ceecb05d69c0506a685272ac7efee7f5264c7
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 * @version $Id$
7 */
8 if (! defined('PHPMYADMIN')) {
9 exit;
12 /**
15 if (isset($plugin_list)) {
16 $plugin_list['yaml'] = array(
17 'text' => 'YAML',
18 'extension' => 'yml',
19 'mime_type' => 'text/yaml',
20 'force_file' => true,
21 'options' => array(
22 array(
23 'type' => 'hidden',
24 'name' => 'data',
27 'options_text' => 'strOptions',
29 } else {
31 /**
32 * Set of functions used to build exports of tables
35 /**
36 * Outputs comment
38 * @param string Text of comment
40 * @return bool Whether it suceeded
42 function PMA_exportComment($text)
44 PMA_exportOutputHandler('# ' . $text . $GLOBALS['crlf']);
45 return true;
48 /**
49 * Outputs export footer
51 * @return bool Whether it suceeded
53 * @access public
55 function PMA_exportFooter()
57 PMA_exportOutputHandler('...' . $GLOBALS['crlf']);
58 return true;
61 /**
62 * Outputs export header
64 * @return bool Whether it suceeded
66 * @access public
68 function PMA_exportHeader()
70 PMA_exportOutputHandler('%YAML 1.1' . $GLOBALS['crlf'] . '---' . $GLOBALS['crlf']);
71 return true;
74 /**
75 * Outputs database header
77 * @param string Database name
79 * @return bool Whether it suceeded
81 * @access public
83 function PMA_exportDBHeader($db)
85 return true;
88 /**
89 * Outputs database footer
91 * @param string Database name
93 * @return bool Whether it suceeded
95 * @access public
97 function PMA_exportDBFooter($db)
99 return true;
103 * Outputs create database database
105 * @param string Database name
107 * @return bool Whether it suceeded
109 * @access public
111 function PMA_exportDBCreate($db)
113 return true;
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
127 * @access public
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));
137 unset($i);
139 $buffer = '';
140 while ($record = PMA_DBI_fetch_row($result)) {
141 $buffer = '-' . $crlf;
142 for ($i = 0; $i < $columns_cnt; $i++) {
143 if (! isset($record[$i])) {
144 continue;
147 $column = $columns[$i];
149 if (is_null($record[$i])) {
150 $buffer .= ' ' . $column . ': null' . $crlf;
151 continue;
154 if (is_numeric($record[$i])) {
155 $buffer .= ' ' . $column . ': ' . $record[$i] . $crlf;
156 continue;
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)) {
167 return FALSE;
170 PMA_DBI_free_result($result);
172 return true;