2.11.1.2 release
[phpmyadmin/arisferyanto.git] / libraries / export / yaml.php
blobe5850ae9fa16c17c72394dd60c702a66978da3c3
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 */
9 /**
12 if (isset($plugin_list)) {
13 $plugin_list['yaml'] = array(
14 'text' => 'YAML',
15 'extension' => 'yml',
16 'mime_type' => 'text/yaml',
17 'force_file' => true,
18 'options' => array(
19 array('type' => 'hidden', 'name' => 'data'),
21 'options_text' => 'strOptions',
23 } else {
25 /**
26 * Set of functions used to build exports of tables
29 /**
30 * Outputs comment
32 * @param string Text of comment
34 * @return bool Whether it suceeded
36 function PMA_exportComment($text)
38 return TRUE;
41 /**
42 * Outputs export footer
44 * @return bool Whether it suceeded
46 * @access public
48 function PMA_exportFooter()
50 return TRUE;
53 /**
54 * Outputs export header
56 * @return bool Whether it suceeded
58 * @access public
60 function PMA_exportHeader()
62 return TRUE;
65 /**
66 * Outputs database header
68 * @param string Database name
70 * @return bool Whether it suceeded
72 * @access public
74 function PMA_exportDBHeader($db)
76 return TRUE;
79 /**
80 * Outputs database footer
82 * @param string Database name
84 * @return bool Whether it suceeded
86 * @access public
88 function PMA_exportDBFooter($db)
90 return TRUE;
93 /**
94 * Outputs create database database
96 * @param string Database name
98 * @return bool Whether it suceeded
100 * @access public
102 function PMA_exportDBCreate($db)
104 return TRUE;
108 * Outputs the content of a table in YAML format
110 * @param string the database name
111 * @param string the table name
112 * @param string the end of line sequence
113 * @param string the url to go back in case of error
114 * @param string SQL query for obtaining data
116 * @return bool Whether it suceeded
118 * @access public
120 function PMA_exportData($db, $table, $crlf, $error_url, $sql_query)
122 $result = PMA_DBI_query($sql_query, null, PMA_DBI_QUERY_UNBUFFERED);
124 $columns_cnt = PMA_DBI_num_fields($result);
125 for ($i = 0; $i < $columns_cnt; $i++) {
126 $columns[$i] = stripslashes(PMA_DBI_field_name($result, $i));
128 unset($i);
130 $cnt = 0;
131 $buffer = '';
132 while ($record = PMA_DBI_fetch_row($result)) {
133 $cnt++;
134 $buffer = $cnt . ":$crlf";
135 for ($i = 0; $i < $columns_cnt; $i++) {
136 if (isset($record[$i]) && !is_null($record[$i])) {
137 $buffer .= ' ' . $columns[$i] . ': ' . htmlspecialchars($record[$i]) . $crlf;
141 if (!PMA_exportOutputHandler($buffer)) {
142 return FALSE;
145 PMA_DBI_free_result($result);
147 return TRUE;