Translation update done using Pootle.
[phpmyadmin/ammaryasirr.git] / libraries / export / php_array.php
blob642475954a1db9bd0eb8728d22e99f282ce467f4
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 /**
4 * Set of functions used to build dumps of tables as PHP Arrays
6 * @package phpMyAdmin-Export
7 * @subpackage PHP
8 */
9 if (! defined('PHPMYADMIN')) {
10 exit;
13 /**
16 if (isset($plugin_list)) {
17 $plugin_list['php_array'] = array(
18 'text' => __('PHP array'),
19 'extension' => 'php',
20 'mime_type' => 'text/plain',
21 'options' => array(
22 array('type' => 'begin_group', 'name' => 'general_opts'),
23 array(
24 'type' => 'hidden',
25 'name' => 'structure_or_data',
27 array('type' => 'end_group')
29 'options_text' => __('Options'),
31 } else {
33 /**
34 * Set of functions used to build exports of tables
37 /**
38 * Outputs export footer
40 * @return bool Whether it suceeded
42 * @access public
44 function PMA_exportFooter()
46 return true;
49 /**
50 * Outputs export header
52 * @return bool Whether it suceeded
54 * @access public
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']
65 return true;
68 /**
69 * Outputs database header
71 * @param string $db Database name
72 * @return bool Whether it suceeded
74 * @access public
76 function PMA_exportDBHeader($db)
78 PMA_exportOutputHandler('//' . $GLOBALS['crlf'] . '// Database "' . $db . '"' . $GLOBALS['crlf'] . '//' . $GLOBALS['crlf']);
79 return true;
82 /**
83 * Outputs database footer
85 * @param string $db Database name
86 * @return bool Whether it suceeded
88 * @access public
90 function PMA_exportDBFooter($db)
92 return true;
95 /**
96 * Outputs CREATE DATABASE statement
98 * @param string $db Database name
99 * @return bool Whether it suceeded
101 * @access public
103 function PMA_exportDBCreate($db)
105 return true;
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
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 $buffer = '';
131 $record_cnt = 0;
132 while ($record = PMA_DBI_fetch_row($result)) {
134 $record_cnt++;
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(';
141 } else {
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) ? '' : ',');
150 $buffer .= ')';
153 $buffer .= $crlf . ');' . $crlf;
154 if (! PMA_exportOutputHandler($buffer)) {
155 return false;
158 PMA_DBI_free_result($result);
160 return true;