2 /* vim: set expandtab sw=4 ts=4 sts=4: */
4 * Set of functions used to build dumps of tables as PHP Arrays
6 * @package phpMyAdmin-Export
9 if (! defined('PHPMYADMIN')) {
16 if (isset($plugin_list)) {
17 $plugin_list['php_array'] = array(
18 'text' => __('PHP array'),
20 'mime_type' => 'text/plain',
22 array('type' => 'begin_group', 'name' => 'general_opts'),
25 'name' => 'structure_or_data',
27 array('type' => 'end_group')
29 'options_text' => __('Options'),
34 * Set of functions used to build exports of tables
38 * Outputs export footer
40 * @return bool Whether it suceeded
44 function PMA_exportFooter()
50 * Outputs export header
52 * @return bool Whether it suceeded
56 function PMA_exportHeader()
58 PMA_exportOutputHandler(
59 '<?php' . $GLOBALS['crlf']
60 . '/**' . $GLOBALS['crlf']
61 . ' * Export to PHP Array plugin for PHPMyAdmin' . $GLOBALS['crlf']
62 . ' * @version 0.2b' . $GLOBALS['crlf']
63 . ' */' . $GLOBALS['crlf'] . $GLOBALS['crlf']
69 * Outputs database header
71 * @param string $db Database name
72 * @return bool Whether it suceeded
76 function PMA_exportDBHeader($db)
78 PMA_exportOutputHandler('//' . $GLOBALS['crlf'] . '// Database "' . $db . '"' . $GLOBALS['crlf'] . '//' . $GLOBALS['crlf']);
83 * Outputs database footer
85 * @param string $db Database name
86 * @return bool Whether it suceeded
90 function PMA_exportDBFooter($db)
96 * Outputs CREATE DATABASE statement
98 * @param string $db Database name
99 * @return bool Whether it suceeded
103 function PMA_exportDBCreate($db)
109 * Outputs the content of a table as a fragment of PHP code
111 * @param string $db database name
112 * @param string $table table name
113 * @param string $crlf the end of line sequence
114 * @param string $error_url the url to go back in case of error
115 * @param string $sql_query SQL query for obtaining data
116 * @return bool Whether it suceeded
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));
132 while ($record = PMA_DBI_fetch_row($result)) {
136 // Output table name as comment if this is the first record of the table
137 if ($record_cnt == 1) {
138 $buffer .= $crlf . '// ' . $db . '.' . $table . $crlf;
139 $buffer .= '$' . $table . ' = array(' . $crlf;
140 $buffer .= ' array(';
142 $buffer .= ',' . $crlf . ' array(';
146 for ($i = 0; $i < $columns_cnt; $i++
) {
147 $buffer .= "'" . $columns[$i]. "'=>" . var_export($record[$i], true) . (($i +
1 >= $columns_cnt) ?
'' : ',');
153 $buffer .= $crlf . ');' . $crlf;
154 if (! PMA_exportOutputHandler($buffer)) {
158 PMA_DBI_free_result($result);