3 * Set of functions used to build dumps of tables as JSON
6 if (! defined('PHPMYADMIN')) {
13 if (isset($plugin_list)) {
14 $plugin_list['json'] = array(
16 'extension' => 'json',
17 'mime_type' => 'text/plain',
19 array('type' => 'begin_group', 'name' => 'general_opts'),
22 'name' => 'structure_or_data',
24 array('type' => 'end_group')
26 'options_text' => __('Options'),
31 * Set of functions used to build exports of tables
37 * @param string Text of comment
39 * @return bool Whether it suceeded
41 function PMA_exportComment($text)
43 PMA_exportOutputHandler('/* ' . $text . ' */' . $GLOBALS['crlf']);
48 * Outputs export footer
50 * @return bool Whether it suceeded
54 function PMA_exportFooter()
60 * Outputs export header
62 * @return bool Whether it suceeded
66 function PMA_exportHeader()
68 PMA_exportOutputHandler(
69 '/**' . $GLOBALS['crlf']
70 . ' Export to JSON plugin for PHPMyAdmin' . $GLOBALS['crlf']
71 . ' @version 0.1' . $GLOBALS['crlf']
72 . ' */' . $GLOBALS['crlf'] . $GLOBALS['crlf']
78 * Outputs database header
80 * @param string Database name
82 * @return bool Whether it suceeded
86 function PMA_exportDBHeader($db)
88 PMA_exportOutputHandler('/* Database \'' . $db . '\' */ ' . $GLOBALS['crlf'] );
93 * Outputs database footer
95 * @param string Database name
97 * @return bool Whether it suceeded
101 function PMA_exportDBFooter($db)
107 * Outputs create database database
109 * @param string Database name
111 * @return bool Whether it suceeded
115 function PMA_exportDBCreate($db)
121 * Outputs the content of a table in YAML format
123 * @param string the database name
124 * @param string the table name
125 * @param string the end of line sequence
126 * @param string the url to go back in case of error
127 * @param string SQL query for obtaining data
129 * @return bool Whether it suceeded
133 function PMA_exportData($db, $table, $crlf, $error_url, $sql_query)
135 $result = PMA_DBI_query($sql_query, null, PMA_DBI_QUERY_UNBUFFERED
);
137 $columns_cnt = PMA_DBI_num_fields($result);
138 for ($i = 0; $i < $columns_cnt; $i++
) {
139 $columns[$i] = stripslashes(PMA_DBI_field_name($result, $i));
145 while ($record = PMA_DBI_fetch_row($result)) {
149 // Output table name as comment if this is the first record of the table
150 if ($record_cnt == 1) {
151 $buffer .= '/* ' . $db . '.' . $table . ' */' . $crlf . $crlf;
157 for ($i = 0; $i < $columns_cnt; $i++
) {
159 $isLastLine = ($i +
1 >= $columns_cnt);
161 $column = $columns[$i];
163 if (is_null($record[$i])) {
164 $buffer .= '"' . $column . '": null' . (! $isLastLine ?
',' : '');
165 } elseif (is_numeric($record[$i])) {
166 $buffer .= '"' . $column . '": ' . $record[$i] . (! $isLastLine ?
',' : '');
168 $buffer .= '"' . $column . '": "' . addslashes($record[$i]) . '"' . (! $isLastLine ?
',' : '');
176 if (! PMA_exportOutputHandler($buffer)) {
180 PMA_DBI_free_result($result);