3 * Set of functions used to build dumps of tables as PHP Arrays
5 * @version 0.2b (20090704)
7 if (! defined('PHPMYADMIN')) {
14 if (isset($plugin_list)) {
15 $plugin_list['php_array'] = array(
16 'text' => __('PHP array'),
18 'mime_type' => 'text/plain',
20 array('type' => 'begin_group', 'name' => 'general_opts'),
23 'name' => 'structure_or_data',
25 array('type' => 'end_group')
27 'options_text' => __('Options'),
32 * Set of functions used to build exports of tables
38 * @param string Text of comment
40 * @return bool Whether it suceeded
42 function PMA_exportComment($text)
44 PMA_exportOutputHandler('// ' . $text . $GLOBALS['crlf']);
49 * Outputs export footer
51 * @return bool Whether it suceeded
55 function PMA_exportFooter()
61 * Outputs export header
63 * @return bool Whether it suceeded
67 function PMA_exportHeader()
69 PMA_exportOutputHandler(
70 '<?php' . $GLOBALS['crlf']
71 . '/**' . $GLOBALS['crlf']
72 . ' * Export to PHP Array plugin for PHPMyAdmin' . $GLOBALS['crlf']
73 . ' * @version 0.2b' . $GLOBALS['crlf']
74 . ' */' . $GLOBALS['crlf'] . $GLOBALS['crlf']
80 * Outputs database header
82 * @param string Database name
84 * @return bool Whether it suceeded
88 function PMA_exportDBHeader($db)
90 PMA_exportOutputHandler('//' . $GLOBALS['crlf'] . '// Database "' . $db . '"' . $GLOBALS['crlf'] . '//' . $GLOBALS['crlf']);
95 * Outputs database footer
97 * @param string Database name
99 * @return bool Whether it suceeded
103 function PMA_exportDBFooter($db)
109 * Outputs create database database
111 * @param string Database name
113 * @return bool Whether it suceeded
117 function PMA_exportDBCreate($db)
123 * Outputs the content of a table in YAML format
125 * @param string the database name
126 * @param string the table name
127 * @param string the end of line sequence
128 * @param string the url to go back in case of error
129 * @param string SQL query for obtaining data
131 * @return bool Whether it suceeded
135 function PMA_exportData($db, $table, $crlf, $error_url, $sql_query)
137 $result = PMA_DBI_query($sql_query, null, PMA_DBI_QUERY_UNBUFFERED
);
139 $columns_cnt = PMA_DBI_num_fields($result);
140 for ($i = 0; $i < $columns_cnt; $i++
) {
141 $columns[$i] = stripslashes(PMA_DBI_field_name($result, $i));
147 while ($record = PMA_DBI_fetch_row($result)) {
151 // Output table name as comment if this is the first record of the table
152 if ($record_cnt == 1) {
153 $buffer .= $crlf . '// ' . $db . '.' . $table . $crlf;
154 $buffer .= '$' . $table . ' = array(' . $crlf;
155 $buffer .= ' array(';
157 $buffer .= ',' . $crlf . ' array(';
161 for ($i = 0; $i < $columns_cnt; $i++
) {
162 $buffer .= "'" . $columns[$i]. "'=>" . var_export($record[$i], true) . (($i +
1 >= $columns_cnt) ?
'' : ',');
168 $buffer .= $crlf . ');' . $crlf;
169 if (! PMA_exportOutputHandler($buffer)) {
173 PMA_DBI_free_result($result);