Merge remote-tracking branch 'origin/master' into drizzle
[phpmyadmin.git] / libraries / export / sql.php
bloba4c6db12f6f9c1210e23cbfbd4803a009b89d772
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 /**
4 * Set of functions used to build SQL dumps of tables
6 * @package phpMyAdmin-Export
7 * @subpackage SQL
8 */
9 if (! defined('PHPMYADMIN')) {
10 exit;
13 /**
16 if (isset($plugin_list)) {
17 $hide_sql = false;
18 $hide_structure = false;
19 if ($plugin_param['export_type'] == 'table' && !$plugin_param['single_table']) {
20 $hide_structure = true;
21 $hide_sql = true;
23 if (!$hide_sql) {
24 $plugin_list['sql'] = array(
25 'text' => __('SQL'),
26 'extension' => 'sql',
27 'mime_type' => 'text/x-sql',
28 'options' => array());
30 $plugin_list['sql']['options'][] = array(
31 'type' => 'begin_group',
32 'name' => 'general_opts');
34 /* comments */
35 $plugin_list['sql']['options'][] = array(
36 'type' => 'begin_subgroup',
37 'subgroup_header' => array(
38 'type' => 'bool',
39 'name' => 'include_comments',
40 'text' => __('Display comments <i>(includes info such as export timestamp, PHP version, and server version)</i>')
41 ));
42 $plugin_list['sql']['options'][] = array(
43 'type' => 'text',
44 'name' => 'header_comment',
45 'text' => __('Additional custom header comment (\n splits lines):')
47 $plugin_list['sql']['options'][] = array(
48 'type' => 'bool',
49 'name' => 'dates',
50 'text' => __('Include a timestamp of when databases were created, last updated, and last checked')
52 if (!empty($GLOBALS['cfgRelation']['relation'])) {
53 $plugin_list['sql']['options'][] = array(
54 'type' => 'bool',
55 'name' => 'relation',
56 'text' => __('Display foreign key relationships')
59 if (!empty($GLOBALS['cfgRelation']['mimework'])) {
60 $plugin_list['sql']['options'][] = array(
61 'type' => 'bool',
62 'name' => 'mime',
63 'text' => __('Display MIME types')
66 $plugin_list['sql']['options'][] = array('type' => 'end_subgroup');
67 /* end comments */
69 /* enclose in a transaction */
70 $plugin_list['sql']['options'][] = array(
71 'type' => 'bool',
72 'name' => 'use_transaction',
73 'text' => __('Enclose export in a transaction'),
74 'doc' => array('programs', 'mysqldump', 'option_mysqldump_single-transaction')
77 /* disable foreign key checks */
78 $plugin_list['sql']['options'][] = array(
79 'type' => 'bool',
80 'name' => 'disable_fk',
81 'text' => __('Disable foreign key checks'),
82 'doc' => array(
83 'manual_MySQL_Database_Administration',
84 'server-system-variables',
85 'sysvar_foreign_key_checks')
88 $plugin_list['sql']['options_text'] = __('Options');
90 /* compatibility maximization */
91 $compats = PMA_DBI_getCompatibilities();
92 if (count($compats) > 0) {
93 $values = array();
94 foreach ($compats as $val) {
95 $values[$val] = $val;
97 $plugin_list['sql']['options'][] = array(
98 'type' => 'select',
99 'name' => 'compatibility',
100 'text' => __('Database system or older MySQL server to maximize output compatibility with:'),
101 'values' => $values,
102 'doc' => array(
103 'manual_MySQL_Database_Administration',
104 'Server_SQL_mode')
106 unset($values);
109 /* server export options */
110 if ($plugin_param['export_type'] == 'server') {
111 $plugin_list['sql']['options'][] = array(
112 'type' => 'bool',
113 'name' => 'drop_database',
114 'text' => sprintf(__('Add %s statement'), '<code>DROP DATABASE</code>')
118 /* what to dump (structure/data/both) */
119 $plugin_list['sql']['options'][] = array(
120 'type' => 'begin_subgroup',
121 'subgroup_header' => array(
122 'type' => 'message_only',
123 'text' => __('Dump table')
125 $plugin_list['sql']['options'][] = array(
126 'type' => 'radio',
127 'name' => 'structure_or_data',
128 'values' => array(
129 'structure' => __('structure'),
130 'data' => __('data'),
131 'structure_and_data' => __('structure and data')
133 $plugin_list['sql']['options'][] = array('type' => 'end_subgroup');
135 $plugin_list['sql']['options'][] = array('type' => 'end_group');
137 /* begin Structure options */
138 if (!$hide_structure) {
139 $plugin_list['sql']['options'][] = array(
140 'type' => 'begin_group',
141 'name' => 'structure',
142 'text' => __('Object creation options'),
143 'force' => 'data'
146 /* begin SQL Statements */
147 $plugin_list['sql']['options'][] = array(
148 'type' => 'begin_subgroup',
149 'subgroup_header' => array(
150 'type' => 'message_only',
151 'name' => 'add_statements',
152 'text' => __('Add statements:')
154 if ($plugin_param['export_type'] == 'table') {
155 if (PMA_Table::isView($GLOBALS['db'], $GLOBALS['table'])) {
156 $drop_clause = '<code>DROP VIEW</code>';
157 } else {
158 $drop_clause = '<code>DROP TABLE</code>';
160 } else {
161 if (PMA_DRIZZLE) {
162 $drop_clause = '<code>DROP TABLE</code>';
163 } else {
164 $drop_clause = '<code>DROP TABLE / VIEW / PROCEDURE / FUNCTION</code>';
165 if (PMA_MYSQL_INT_VERSION > 50100) {
166 $drop_clause .= '<code> / EVENT</code>';
170 $plugin_list['sql']['options'][] = array(
171 'type' => 'bool',
172 'name' => 'drop_table',
173 'text' => sprintf(__('Add %s statement'), $drop_clause)
175 // Drizzle doesn't support procedures and functions
176 if (!PMA_DRIZZLE) {
177 $plugin_list['sql']['options'][] = array(
178 'type' => 'bool',
179 'name' => 'procedure_function',
180 'text' => sprintf(__('Add %s statement'), '<code>CREATE PROCEDURE / FUNCTION' . (PMA_MYSQL_INT_VERSION > 50100 ? ' / EVENT</code>' : '</code>'))
184 /* begin CREATE TABLE statements*/
185 $plugin_list['sql']['options'][] = array(
186 'type' => 'begin_subgroup',
187 'subgroup_header' => array(
188 'type' => 'bool',
189 'name' => 'create_table_statements',
190 'text' => __('<code>CREATE TABLE</code> options:')
192 $plugin_list['sql']['options'][] = array(
193 'type' => 'bool',
194 'name' => 'if_not_exists',
195 'text' => '<code>IF NOT EXISTS</code>'
197 $plugin_list['sql']['options'][] = array(
198 'type' => 'bool',
199 'name' => 'auto_increment',
200 'text' => '<code>AUTO_INCREMENT</code>'
202 $plugin_list['sql']['options'][] = array('type' => 'end_subgroup');
203 /* end CREATE TABLE statements */
205 $plugin_list['sql']['options'][] = array('type' => 'end_subgroup');
206 /* end SQL statements */
208 $plugin_list['sql']['options'][] = array(
209 'type' => 'bool',
210 'name' => 'backquotes',
211 'text' => __('Enclose table and field names with backquotes <i>(Protects field and table names formed with special characters or keywords)</i>')
214 $plugin_list['sql']['options'][] = array('type' => 'end_group');
216 /* end Structure options */
218 /* begin Data options */
219 $plugin_list['sql']['options'][] = array(
220 'type' => 'begin_group',
221 'name' => 'data',
222 'text' => __('Data dump options'),
223 'force' => 'structure'
226 /* begin SQL statements */
227 $plugin_list['sql']['options'][] = array(
228 'type' => 'begin_subgroup',
229 'subgroup_header' => array(
230 'type' => 'message_only',
231 'text' => __('Instead of <code>INSERT</code> statements, use:')
233 // Not supported in Drizzle
234 if (!PMA_DRIZZLE) {
235 $plugin_list['sql']['options'][] = array(
236 'type' => 'bool',
237 'name' => 'delayed',
238 'text' => __('<code>INSERT DELAYED</code> statements'),
239 'doc' => array('manual_MySQL_Database_Administration', 'insert_delayed')
242 $plugin_list['sql']['options'][] = array(
243 'type' => 'bool',
244 'name' => 'ignore',
245 'text' => __('<code>INSERT IGNORE</code> statements'),
246 'doc' => array('manual_MySQL_Database_Administration', 'insert')
248 $plugin_list['sql']['options'][] = array('type' => 'end_subgroup');
249 /* end SQL statements */
251 /* Function to use when dumping data */
252 $plugin_list['sql']['options'][] = array(
253 'type' => 'select',
254 'name' => 'type',
255 'text' => __('Function to use when dumping data:'),
256 'values' => array(
257 'INSERT' => 'INSERT',
258 'UPDATE' => 'UPDATE',
259 'REPLACE' => 'REPLACE'
263 /* Syntax to use when inserting data */
264 $plugin_list['sql']['options'][] = array(
265 'type' => 'begin_subgroup',
266 'subgroup_header' => array(
267 'type' => 'message_only',
268 'text' => __('Syntax to use when inserting data:')
270 $plugin_list['sql']['options'][] = array(
271 'type' => 'radio',
272 'name' => 'insert_syntax',
273 'values' => array(
274 'complete' => __('include column names in every <code>INSERT</code> statement <br /> &nbsp; &nbsp; &nbsp; Example: <code>INSERT INTO tbl_name (col_A,col_B,col_C) VALUES (1,2,3)</code>'),
275 'extended' => __('insert multiple rows in every <code>INSERT</code> statement<br /> &nbsp; &nbsp; &nbsp; Example: <code>INSERT INTO tbl_name VALUES (1,2,3), (4,5,6), (7,8,9)</code>'),
276 'both' => __('both of the above<br /> &nbsp; &nbsp; &nbsp; Example: <code>INSERT INTO tbl_name (col_A,col_B) VALUES (1,2,3), (4,5,6), (7,8,9)</code>'),
277 'none' => __('neither of the above<br /> &nbsp; &nbsp; &nbsp; Example: <code>INSERT INTO tbl_name VALUES (1,2,3)</code>')
279 $plugin_list['sql']['options'][] = array('type' => 'end_subgroup');
281 /* Max length of query */
282 $plugin_list['sql']['options'][] = array(
283 'type' => 'text',
284 'name' => 'max_query_size',
285 'text' => __('Maximal length of created query')
288 /* Dump binary columns in hexadecimal */
289 $plugin_list['sql']['options'][] = array(
290 'type' => 'bool',
291 'name' => 'hex_for_blob',
292 'text' => __('Dump binary columns in hexadecimal notation <i>(for example, "abc" becomes 0x616263)</i>')
295 // Drizzle works only with UTC timezone
296 if (!PMA_DRIZZLE) {
297 /* Dump time in UTC */
298 $plugin_list['sql']['options'][] = array(
299 'type' => 'bool',
300 'name' => 'utc_time',
301 'text' => __('Dump TIMESTAMP columns in UTC <i>(enables TIMESTAMP columns to be dumped and reloaded between servers in different time zones)</i>')
305 $plugin_list['sql']['options'][] = array('type' => 'end_group');
306 /* end Data options */
308 } else {
311 * Avoids undefined variables, use NULL so isset() returns false
313 if (! isset($sql_backquotes)) {
314 $sql_backquotes = null;
318 * Exports routines (procedures and functions)
320 * @param string $db
321 * @return bool Whether it suceeded
323 * @access public
325 function PMA_exportRoutines($db) {
326 global $crlf;
328 $text = '';
329 $delimiter = '$$';
331 $procedure_names = PMA_DBI_get_procedures_or_functions($db, 'PROCEDURE');
332 $function_names = PMA_DBI_get_procedures_or_functions($db, 'FUNCTION');
334 if ($procedure_names || $function_names) {
335 $text .= $crlf
336 . 'DELIMITER ' . $delimiter . $crlf;
339 if ($procedure_names) {
340 $text .=
341 PMA_exportComment()
342 . PMA_exportComment(__('Procedures'))
343 . PMA_exportComment();
345 foreach ($procedure_names as $procedure_name) {
346 if (! empty($GLOBALS['sql_drop_table'])) {
347 $text .= 'DROP PROCEDURE IF EXISTS '
348 . PMA_backquote($procedure_name)
349 . $delimiter . $crlf;
351 $text .= PMA_DBI_get_definition($db, 'PROCEDURE', $procedure_name)
352 . $delimiter . $crlf . $crlf;
356 if ($function_names) {
357 $text .=
358 PMA_exportComment()
359 . PMA_exportComment(__('Functions'))
360 . PMA_exportComment();
362 foreach ($function_names as $function_name) {
363 if (! empty($GLOBALS['sql_drop_table'])) {
364 $text .= 'DROP FUNCTION IF EXISTS '
365 . PMA_backquote($function_name)
366 . $delimiter . $crlf;
368 $text .= PMA_DBI_get_definition($db, 'FUNCTION', $function_name)
369 . $delimiter . $crlf . $crlf;
373 if ($procedure_names || $function_names) {
374 $text .= 'DELIMITER ;' . $crlf;
377 if (! empty($text)) {
378 return PMA_exportOutputHandler($text);
379 } else {
380 return false;
385 * Possibly outputs comment
387 * @param string $text Text of comment
388 * @return string The formatted comment
390 * @access private
392 function PMA_exportComment($text = '')
394 if (isset($GLOBALS['sql_include_comments']) && $GLOBALS['sql_include_comments']) {
395 // see http://dev.mysql.com/doc/refman/5.0/en/ansi-diff-comments.html
396 return '--' . (empty($text) ? '' : ' ') . $text . $GLOBALS['crlf'];
397 } else {
398 return '';
403 * Possibly outputs CRLF
405 * @return string $crlf or nothing
407 * @access private
409 function PMA_possibleCRLF()
411 if (isset($GLOBALS['sql_include_comments']) && $GLOBALS['sql_include_comments']) {
412 return $GLOBALS['crlf'];
413 } else {
414 return '';
419 * Outputs export footer
421 * @return bool Whether it suceeded
423 * @access public
425 function PMA_exportFooter()
427 global $crlf;
428 global $mysql_charset_map;
430 $foot = '';
432 if (isset($GLOBALS['sql_disable_fk'])) {
433 $foot .= 'SET FOREIGN_KEY_CHECKS=1;' . $crlf;
436 if (isset($GLOBALS['sql_use_transaction'])) {
437 $foot .= 'COMMIT;' . $crlf;
440 // restore connection settings
441 $charset_of_file = isset($GLOBALS['charset_of_file']) ? $GLOBALS['charset_of_file'] : '';
442 if (!empty($GLOBALS['asfile']) && isset($mysql_charset_map[$charset_of_file]) && !PMA_DRIZZLE) {
443 $foot .= $crlf
444 . '/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;' . $crlf
445 . '/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;' . $crlf
446 . '/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;' . $crlf;
449 /* Restore timezone */
450 if (isset($GLOBALS['sql_utc_time']) && $GLOBALS['sql_utc_time']) {
451 PMA_DBI_query('SET time_zone = "' . $GLOBALS['old_tz'] . '"');
454 return PMA_exportOutputHandler($foot);
458 * Outputs export header
460 * @return bool Whether it suceeded
462 * @access public
464 function PMA_exportHeader()
466 global $crlf;
467 global $cfg;
468 global $mysql_charset_map;
470 if (isset($GLOBALS['sql_compatibility'])) {
471 $tmp_compat = $GLOBALS['sql_compatibility'];
472 if ($tmp_compat == 'NONE') {
473 $tmp_compat = '';
475 PMA_DBI_try_query('SET SQL_MODE="' . $tmp_compat . '"');
476 unset($tmp_compat);
478 $head = PMA_exportComment('phpMyAdmin SQL Dump')
479 . PMA_exportComment('version ' . PMA_VERSION)
480 . PMA_exportComment('http://www.phpmyadmin.net')
481 . PMA_exportComment();
482 $host_string = __('Host') . ': ' . $cfg['Server']['host'];
483 if (!empty($cfg['Server']['port'])) {
484 $host_string .= ':' . $cfg['Server']['port'];
486 $head .= PMA_exportComment($host_string);
487 $head .= PMA_exportComment(__('Generation Time')
488 . ': ' . PMA_localisedDate())
489 . PMA_exportComment(__('Server version') . ': ' . PMA_MYSQL_STR_VERSION)
490 . PMA_exportComment(__('PHP Version') . ': ' . phpversion())
491 . PMA_possibleCRLF();
493 if (isset($GLOBALS['sql_header_comment']) && !empty($GLOBALS['sql_header_comment'])) {
494 // '\n' is not a newline (like "\n" would be), it's the characters
495 // backslash and n, as explained on the export interface
496 $lines = explode('\n', $GLOBALS['sql_header_comment']);
497 $head .= PMA_exportComment();
498 foreach ($lines as $one_line) {
499 $head .= PMA_exportComment($one_line);
501 $head .= PMA_exportComment();
504 if (isset($GLOBALS['sql_disable_fk'])) {
505 $head .= 'SET FOREIGN_KEY_CHECKS=0;' . $crlf;
508 /* We want exported AUTO_INCREMENT fields to have still same value, do this only for recent MySQL exports */
509 if ((!isset($GLOBALS['sql_compatibility']) || $GLOBALS['sql_compatibility'] == 'NONE')
510 && !PMA_DRIZZLE) {
511 $head .= 'SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO";' . $crlf;
514 if (isset($GLOBALS['sql_use_transaction'])) {
515 $head .= 'SET AUTOCOMMIT=0;' . $crlf
516 . 'START TRANSACTION;' . $crlf;
520 /* Change timezone if we should export timestamps in UTC */
521 if (isset($GLOBALS['sql_utc_time']) && $GLOBALS['sql_utc_time']) {
522 $head .= 'SET time_zone = "+00:00";' . $crlf;
523 $GLOBALS['old_tz'] = PMA_DBI_fetch_value('SELECT @@session.time_zone');
524 PMA_DBI_query('SET time_zone = "+00:00"');
527 $head .= PMA_possibleCRLF();
529 if (! empty($GLOBALS['asfile']) && !PMA_DRIZZLE) {
530 // we are saving as file, therefore we provide charset information
531 // so that a utility like the mysql client can interpret
532 // the file correctly
533 if (isset($GLOBALS['charset_of_file']) && isset($mysql_charset_map[$GLOBALS['charset_of_file']])) {
534 // we got a charset from the export dialog
535 $set_names = $mysql_charset_map[$GLOBALS['charset_of_file']];
536 } else {
537 // by default we use the connection charset
538 $set_names = $mysql_charset_map['utf-8'];
540 $head .= $crlf
541 . '/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;' . $crlf
542 . '/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;' . $crlf
543 . '/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;' . $crlf
544 . '/*!40101 SET NAMES ' . $set_names . ' */;' . $crlf . $crlf;
547 return PMA_exportOutputHandler($head);
551 * Outputs CREATE DATABASE statement
553 * @param string $db Database name
554 * @return bool Whether it suceeded
556 * @access public
558 function PMA_exportDBCreate($db)
560 global $crlf;
561 if (isset($GLOBALS['sql_drop_database'])) {
562 if (!PMA_exportOutputHandler('DROP DATABASE ' . (isset($GLOBALS['sql_backquotes']) ? PMA_backquote($db) : $db) . ';' . $crlf)) {
563 return false;
566 $create_query = 'CREATE DATABASE ' . (isset($GLOBALS['sql_backquotes']) ? PMA_backquote($db) : $db);
567 $collation = PMA_getDbCollation($db);
568 if (PMA_DRIZZLE) {
569 $create_query .= ' COLLATE ' . $collation;
570 } else {
571 if (strpos($collation, '_')) {
572 $create_query .= ' DEFAULT CHARACTER SET ' . substr($collation, 0, strpos($collation, '_')) . ' COLLATE ' . $collation;
573 } else {
574 $create_query .= ' DEFAULT CHARACTER SET ' . $collation;
577 $create_query .= ';' . $crlf;
578 if (!PMA_exportOutputHandler($create_query)) {
579 return false;
581 if (isset($GLOBALS['sql_backquotes'])
582 && ((isset($GLOBALS['sql_compatibility']) && $GLOBALS['sql_compatibility'] == 'NONE') || PMA_DRIZZLE)) {
583 $result = PMA_exportOutputHandler('USE ' . PMA_backquote($db) . ';' . $crlf);
584 } else {
585 $result = PMA_exportOutputHandler('USE ' . $db . ';' . $crlf);
588 return $result;
592 * Outputs database header
594 * @param string $db Database name
595 * @return bool Whether it suceeded
597 * @access public
599 function PMA_exportDBHeader($db)
601 $head = PMA_exportComment()
602 . PMA_exportComment(__('Database') . ': ' . (isset($GLOBALS['sql_backquotes']) ? PMA_backquote($db) : '\'' . $db . '\''))
603 . PMA_exportComment();
604 return PMA_exportOutputHandler($head);
608 * Outputs database footer
610 * @param string $db Database name
611 * @return bool Whether it suceeded
613 * @access public
615 function PMA_exportDBFooter($db)
617 global $crlf;
619 $result = true;
620 if (isset($GLOBALS['sql_constraints'])) {
621 $result = PMA_exportOutputHandler($GLOBALS['sql_constraints']);
622 unset($GLOBALS['sql_constraints']);
625 if (($GLOBALS['sql_structure_or_data'] == 'structure' || $GLOBALS['sql_structure_or_data'] == 'structure_and_data') && isset($GLOBALS['sql_procedure_function'])) {
626 $text = '';
627 $delimiter = '$$';
629 if (PMA_MYSQL_INT_VERSION > 50100) {
630 $event_names = PMA_DBI_fetch_result('SELECT EVENT_NAME FROM information_schema.EVENTS WHERE EVENT_SCHEMA= \'' . PMA_sqlAddSlashes($db,true) . '\';');
631 } else {
632 $event_names = array();
635 if ($event_names) {
636 $text .= $crlf
637 . 'DELIMITER ' . $delimiter . $crlf;
639 $text .=
640 PMA_exportComment()
641 . PMA_exportComment(__('Events'))
642 . PMA_exportComment();
644 foreach ($event_names as $event_name) {
645 if (! empty($GLOBALS['sql_drop_table'])) {
646 $text .= 'DROP EVENT ' . PMA_backquote($event_name) . $delimiter . $crlf;
648 $text .= PMA_DBI_get_definition($db, 'EVENT', $event_name) . $delimiter . $crlf . $crlf;
651 $text .= 'DELIMITER ;' . $crlf;
654 if (! empty($text)) {
655 $result = PMA_exportOutputHandler($text);
658 return $result;
662 * Returns a stand-in CREATE definition to resolve view dependencies
664 * @param string $db the database name
665 * @param string $view the view name
666 * @param string $crlf the end of line sequence
667 * @return string resulting definition
669 * @access public
671 function PMA_getTableDefStandIn($db, $view, $crlf) {
672 $create_query = '';
673 if (! empty($GLOBALS['sql_drop_table'])) {
674 $create_query .= 'DROP VIEW IF EXISTS ' . PMA_backquote($view) . ';' . $crlf;
677 $create_query .= 'CREATE TABLE ';
679 if (isset($GLOBALS['sql_if_not_exists']) && $GLOBALS['sql_if_not_exists']) {
680 $create_query .= 'IF NOT EXISTS ';
682 $create_query .= PMA_backquote($view) . ' (' . $crlf;
683 $tmp = array();
684 $columns = PMA_DBI_get_columns_full($db, $view);
685 foreach ($columns as $column_name => $definition) {
686 $tmp[] = PMA_backquote($column_name) . ' ' . $definition['Type'] . $crlf;
688 $create_query .= implode(',', $tmp) . ');';
689 return($create_query);
693 * Returns $table's CREATE definition
695 * @param string $db the database name
696 * @param string $table the table name
697 * @param string $crlf the end of line sequence
698 * @param string $error_url the url to go back in case of error
699 * @param bool $show_dates whether to include creation/update/check dates
700 * @param bool $add_semicolon whether to add semicolon and end-of-line at the end
701 * @param bool $view whether we're handling a view
702 * @return string resulting schema
704 * @access public
706 function PMA_getTableDef($db, $table, $crlf, $error_url, $show_dates = false, $add_semicolon = true, $view = false)
708 global $sql_drop_table;
709 global $sql_backquotes;
710 global $sql_constraints_query; // just the text of the query
711 global $sql_drop_foreign_keys;
713 $schema_create = '';
714 $auto_increment = '';
715 $new_crlf = $crlf;
717 // need to use PMA_DBI_QUERY_STORE with PMA_DBI_num_rows() in mysqli
718 $result = PMA_DBI_query('SHOW TABLE STATUS FROM ' . PMA_backquote($db) . ' LIKE \'' . PMA_sqlAddSlashes($table, true) . '\'', null, PMA_DBI_QUERY_STORE);
719 if ($result != false) {
720 if (PMA_DBI_num_rows($result) > 0) {
721 $tmpres = PMA_DBI_fetch_assoc($result);
722 if (PMA_DRIZZLE && $show_dates) {
723 // Drizzle doesn't give Create_time and Update_time in SHOW TABLE STATUS, add it
724 $sql ="SELECT
725 TABLE_CREATION_TIME AS Create_time,
726 TABLE_UPDATE_TIME AS Update_time
727 FROM data_dictionary.TABLES
728 WHERE TABLE_SCHEMA = '" . PMA_sqlAddSlashes($db) . "'
729 AND TABLE_NAME = '" . PMA_sqlAddSlashes($table) . "'";
730 $tmpres = array_merge(PMA_DBI_fetch_single_row($sql), $tmpres);
732 // Here we optionally add the AUTO_INCREMENT next value,
733 // but starting with MySQL 5.0.24, the clause is already included
734 // in SHOW CREATE TABLE so we'll remove it below
735 // It's required for Drizzle because SHOW CREATE TABLE uses
736 // the value from table's creation time
737 if (isset($GLOBALS['sql_auto_increment']) && !empty($tmpres['Auto_increment'])) {
738 $auto_increment .= ' AUTO_INCREMENT=' . $tmpres['Auto_increment'] . ' ';
741 if ($show_dates && isset($tmpres['Create_time']) && !empty($tmpres['Create_time'])) {
742 $schema_create .= PMA_exportComment(__('Creation') . ': ' . PMA_localisedDate(strtotime($tmpres['Create_time'])));
743 $new_crlf = PMA_exportComment() . $crlf;
746 if ($show_dates && isset($tmpres['Update_time']) && !empty($tmpres['Update_time'])) {
747 $schema_create .= PMA_exportComment(__('Last update') . ': ' . PMA_localisedDate(strtotime($tmpres['Update_time'])));
748 $new_crlf = PMA_exportComment() . $crlf;
751 if ($show_dates && isset($tmpres['Check_time']) && !empty($tmpres['Check_time'])) {
752 $schema_create .= PMA_exportComment(__('Last check') . ': ' . PMA_localisedDate(strtotime($tmpres['Check_time'])));
753 $new_crlf = PMA_exportComment() . $crlf;
756 PMA_DBI_free_result($result);
759 $schema_create .= $new_crlf;
761 // no need to generate a DROP VIEW here, it was done earlier
762 if (! empty($sql_drop_table) && ! PMA_Table::isView($db,$table)) {
763 $schema_create .= 'DROP TABLE IF EXISTS ' . PMA_backquote($table, $sql_backquotes) . ';' . $crlf;
766 // Complete table dump,
767 // Whether to quote table and fields names or not
768 // Drizzle always quotes names
769 if (!PMA_DRIZZLE) {
770 if ($sql_backquotes) {
771 PMA_DBI_query('SET SQL_QUOTE_SHOW_CREATE = 1');
772 } else {
773 PMA_DBI_query('SET SQL_QUOTE_SHOW_CREATE = 0');
777 // I don't see the reason why this unbuffered query could cause problems,
778 // because SHOW CREATE TABLE returns only one row, and we free the
779 // results below. Nonetheless, we got 2 user reports about this
780 // (see bug 1562533) so I remove the unbuffered mode.
781 //$result = PMA_DBI_query('SHOW CREATE TABLE ' . PMA_backquote($db) . '.' . PMA_backquote($table), null, PMA_DBI_QUERY_UNBUFFERED);
783 // Note: SHOW CREATE TABLE, at least in MySQL 5.1.23, does not
784 // produce a displayable result for the default value of a BIT
785 // field, nor does the mysqldump command. See MySQL bug 35796
786 $result = PMA_DBI_try_query('SHOW CREATE TABLE ' . PMA_backquote($db) . '.' . PMA_backquote($table));
787 // an error can happen, for example the table is crashed
788 $tmp_error = PMA_DBI_getError();
789 if ($tmp_error) {
790 return PMA_exportComment(__('in use') . '(' . $tmp_error . ')');
793 if ($result != false && ($row = PMA_DBI_fetch_row($result))) {
794 $create_query = $row[1];
795 unset($row);
797 // Convert end of line chars to one that we want (note that MySQL doesn't return query it will accept in all cases)
798 if (strpos($create_query, "(\r\n ")) {
799 $create_query = str_replace("\r\n", $crlf, $create_query);
800 } elseif (strpos($create_query, "(\n ")) {
801 $create_query = str_replace("\n", $crlf, $create_query);
802 } elseif (strpos($create_query, "(\r ")) {
803 $create_query = str_replace("\r", $crlf, $create_query);
807 * Drop database name from VIEW creation.
809 * This is a bit tricky, but we need to issue SHOW CREATE TABLE with
810 * database name, but we don't want name to show up in CREATE VIEW
811 * statement.
813 if ($view) {
814 $create_query = preg_replace('/' . PMA_backquote($db) . '\./', '', $create_query);
817 // Should we use IF NOT EXISTS?
818 if (isset($GLOBALS['sql_if_not_exists'])) {
819 $create_query = preg_replace('/^CREATE TABLE/', 'CREATE TABLE IF NOT EXISTS', $create_query);
822 // Drizzle (checked on 2011.03.13) returns ROW_FORMAT surrounded with quotes, which is not accepted by parser
823 if (PMA_DRIZZLE) {
824 $create_query = preg_replace('/ROW_FORMAT=\'(\S+)\'/', 'ROW_FORMAT=$1', $create_query);
827 // are there any constraints to cut out?
828 if (preg_match('@CONSTRAINT|FOREIGN[\s]+KEY@', $create_query)) {
830 // Split the query into lines, so we can easily handle it. We know lines are separated by $crlf (done few lines above).
831 $sql_lines = explode($crlf, $create_query);
832 $sql_count = count($sql_lines);
834 // lets find first line with constraints
835 for ($i = 0; $i < $sql_count; $i++) {
836 if (preg_match('@^[\s]*(CONSTRAINT|FOREIGN[\s]+KEY)@', $sql_lines[$i])) {
837 break;
841 // If we really found a constraint
842 if ($i != $sql_count) {
844 // remove , from the end of create statement
845 $sql_lines[$i - 1] = preg_replace('@,$@', '', $sql_lines[$i - 1]);
847 // prepare variable for constraints
848 if (!isset($sql_constraints)) {
849 if (isset($GLOBALS['no_constraints_comments'])) {
850 $sql_constraints = '';
851 } else {
852 $sql_constraints = $crlf
853 . PMA_exportComment()
854 . PMA_exportComment(__('Constraints for dumped tables'))
855 . PMA_exportComment();
859 // comments for current table
860 if (!isset($GLOBALS['no_constraints_comments'])) {
861 $sql_constraints .= $crlf
862 . PMA_exportComment()
863 . PMA_exportComment(__('Constraints for table') . ' ' . PMA_backquote($table))
864 . PMA_exportComment();
867 // let's do the work
868 $sql_constraints_query .= 'ALTER TABLE ' . PMA_backquote($table) . $crlf;
869 $sql_constraints .= 'ALTER TABLE ' . PMA_backquote($table) . $crlf;
870 $sql_drop_foreign_keys .= 'ALTER TABLE ' . PMA_backquote($db) . '.' . PMA_backquote($table) . $crlf;
872 $first = true;
873 for ($j = $i; $j < $sql_count; $j++) {
874 if (preg_match('@CONSTRAINT|FOREIGN[\s]+KEY@', $sql_lines[$j])) {
875 if (!$first) {
876 $sql_constraints .= $crlf;
878 if (strpos($sql_lines[$j], 'CONSTRAINT') === false) {
879 $tmp_str = preg_replace('/(FOREIGN[\s]+KEY)/', 'ADD \1', $sql_lines[$j]);
880 $sql_constraints_query .= $tmp_str;
881 $sql_constraints .= $tmp_str;
882 } else {
883 $tmp_str = preg_replace('/(CONSTRAINT)/', 'ADD \1', $sql_lines[$j]);
884 $sql_constraints_query .= $tmp_str;
885 $sql_constraints .= $tmp_str;
886 preg_match('/(CONSTRAINT)([\s])([\S]*)([\s])/', $sql_lines[$j], $matches);
887 if (! $first) {
888 $sql_drop_foreign_keys .= ', ';
890 $sql_drop_foreign_keys .= 'DROP FOREIGN KEY ' . $matches[3];
892 $first = false;
893 } else {
894 break;
897 $sql_constraints .= ';' . $crlf;
898 $sql_constraints_query .= ';';
900 $create_query = implode($crlf, array_slice($sql_lines, 0, $i)) . $crlf . implode($crlf, array_slice($sql_lines, $j, $sql_count - 1));
901 unset($sql_lines);
904 $schema_create .= $create_query;
907 // remove a possible "AUTO_INCREMENT = value" clause
908 // that could be there starting with MySQL 5.0.24
909 // in Drizzle it's useless as it contains the value given at table creation time
910 $schema_create = preg_replace('/AUTO_INCREMENT\s*=\s*([0-9])+/', '', $schema_create);
912 $schema_create .= $auto_increment;
914 PMA_DBI_free_result($result);
915 return $schema_create . ($add_semicolon ? ';' . $crlf : '');
916 } // end of the 'PMA_getTableDef()' function
919 * Returns $table's comments, relations etc.
921 * @param string $db database name
922 * @param string $table table name
923 * @param string $crlf end of line sequence
924 * @param bool $do_relation whether to include relation comments
925 * @param bool $do_mime whether to include mime comments
926 * @return string resulting comments
928 * @access private
930 function PMA_getTableComments($db, $table, $crlf, $do_relation = false, $do_mime = false)
932 global $cfgRelation;
933 global $sql_backquotes;
934 global $sql_constraints;
936 $schema_create = '';
938 // Check if we can use Relations
939 if ($do_relation && !empty($cfgRelation['relation'])) {
940 // Find which tables are related with the current one and write it in
941 // an array
942 $res_rel = PMA_getForeigners($db, $table);
944 if ($res_rel && count($res_rel) > 0) {
945 $have_rel = true;
946 } else {
947 $have_rel = false;
949 } else {
950 $have_rel = false;
951 } // end if
953 if ($do_mime && $cfgRelation['mimework']) {
954 if (!($mime_map = PMA_getMIME($db, $table, true))) {
955 unset($mime_map);
959 if (isset($mime_map) && count($mime_map) > 0) {
960 $schema_create .= PMA_possibleCRLF()
961 . PMA_exportComment()
962 . PMA_exportComment(__('MIME TYPES FOR TABLE'). ' ' . PMA_backquote($table, $sql_backquotes) . ':');
963 @reset($mime_map);
964 foreach ($mime_map AS $mime_field => $mime) {
965 $schema_create .= PMA_exportComment(' ' . PMA_backquote($mime_field, $sql_backquotes))
966 . PMA_exportComment(' ' . PMA_backquote($mime['mimetype'], $sql_backquotes));
968 $schema_create .= PMA_exportComment();
971 if ($have_rel) {
972 $schema_create .= PMA_possibleCRLF()
973 . PMA_exportComment()
974 . PMA_exportComment(__('RELATIONS FOR TABLE'). ' ' . PMA_backquote($table, $sql_backquotes) . ':');
975 foreach ($res_rel AS $rel_field => $rel) {
976 $schema_create .= PMA_exportComment(' ' . PMA_backquote($rel_field, $sql_backquotes))
977 . PMA_exportComment(' ' . PMA_backquote($rel['foreign_table'], $sql_backquotes)
978 . ' -> ' . PMA_backquote($rel['foreign_field'], $sql_backquotes));
980 $schema_create .= PMA_exportComment();
983 return $schema_create;
985 } // end of the 'PMA_getTableComments()' function
988 * Outputs table's structure
990 * @param string $db database name
991 * @param string $table table name
992 * @param string $crlf the end of line sequence
993 * @param string $error_url the url to go back in case of error
994 * @param bool $relation whether to include relation comments
995 * @param bool $comments whether to include the pmadb-style column comments
996 * as comments in the structure; this is deprecated
997 * but the parameter is left here because export.php
998 * calls PMA_exportStructure() also for other export
999 * types which use this parameter
1000 * @param bool $mime whether to include mime comments
1001 * @param bool $dates whether to include creation/update/check dates
1002 * @param string $export_mode 'create_table', 'triggers', 'create_view', 'stand_in'
1003 * @param string $export_type 'server', 'database', 'table'
1004 * @return bool Whether it suceeded
1006 * @access public
1008 function PMA_exportStructure($db, $table, $crlf, $error_url, $relation = false, $comments = false, $mime = false, $dates = false, $export_mode, $export_type)
1010 $formatted_table_name = (isset($GLOBALS['sql_backquotes']))
1011 ? PMA_backquote($table)
1012 : '\'' . $table . '\'';
1013 $dump = PMA_possibleCRLF()
1014 . PMA_exportComment(str_repeat('-', 56))
1015 . PMA_possibleCRLF()
1016 . PMA_exportComment();
1018 switch($export_mode) {
1019 case 'create_table':
1020 $dump .= PMA_exportComment(__('Table structure for table') . ' ' . $formatted_table_name);
1021 $dump .= PMA_exportComment();
1022 $dump .= PMA_getTableDef($db, $table, $crlf, $error_url, $dates);
1023 $dump .= PMA_getTableComments($db, $table, $crlf, $relation, $mime);
1024 break;
1025 case 'triggers':
1026 $dump = '';
1027 $triggers = PMA_DBI_get_triggers($db, $table);
1028 if ($triggers) {
1029 $dump .= PMA_possibleCRLF()
1030 . PMA_exportComment()
1031 . PMA_exportComment(__('Triggers') . ' ' . $formatted_table_name)
1032 . PMA_exportComment();
1033 $delimiter = '//';
1034 foreach ($triggers as $trigger) {
1035 $dump .= $trigger['drop'] . ';' . $crlf;
1036 $dump .= 'DELIMITER ' . $delimiter . $crlf;
1037 $dump .= $trigger['create'];
1038 $dump .= 'DELIMITER ;' . $crlf;
1041 break;
1042 case 'create_view':
1043 $dump .= PMA_exportComment(__('Structure for view') . ' ' . $formatted_table_name)
1044 . PMA_exportComment();
1045 // delete the stand-in table previously created (if any)
1046 if ($export_type != 'table') {
1047 $dump .= 'DROP TABLE IF EXISTS ' . PMA_backquote($table) . ';' . $crlf;
1049 $dump .= PMA_getTableDef($db, $table, $crlf, $error_url, $dates, true, true);
1050 break;
1051 case 'stand_in':
1052 $dump .= PMA_exportComment(__('Stand-in structure for view') . ' ' . $formatted_table_name)
1053 . PMA_exportComment();
1054 // export a stand-in definition to resolve view dependencies
1055 $dump .= PMA_getTableDefStandIn($db, $table, $crlf);
1056 } // end switch
1058 // this one is built by PMA_getTableDef() to use in table copy/move
1059 // but not in the case of export
1060 unset($GLOBALS['sql_constraints_query']);
1062 return PMA_exportOutputHandler($dump);
1066 * Outputs the content of a table in SQL format
1068 * @param string $db database name
1069 * @param string $table table name
1070 * @param string $crlf the end of line sequence
1071 * @param string $error_url the url to go back in case of error
1072 * @param string $sql_query SQL query for obtaining data
1073 * @return bool Whether it suceeded
1075 * @access public
1077 function PMA_exportData($db, $table, $crlf, $error_url, $sql_query)
1079 global $sql_backquotes;
1080 global $current_row;
1082 $formatted_table_name = (isset($GLOBALS['sql_backquotes']))
1083 ? PMA_backquote($table)
1084 : '\'' . $table . '\'';
1086 // Do not export data for a VIEW
1087 // (For a VIEW, this is called only when exporting a single VIEW)
1088 if (PMA_Table::isView($db, $table)) {
1089 $head = PMA_possibleCRLF()
1090 . PMA_exportComment()
1091 . PMA_exportComment('VIEW ' . ' ' . $formatted_table_name)
1092 . PMA_exportComment(__('Data') . ': ' . __('None'))
1093 . PMA_exportComment()
1094 . PMA_possibleCRLF();
1096 if (! PMA_exportOutputHandler($head)) {
1097 return false;
1099 return true;
1102 // analyze the query to get the true column names, not the aliases
1103 // (this fixes an undefined index, also if Complete inserts
1104 // are used, we did not get the true column name in case of aliases)
1105 $analyzed_sql = PMA_SQP_analyze(PMA_SQP_parse($sql_query));
1107 $result = PMA_DBI_try_query($sql_query, null, PMA_DBI_QUERY_UNBUFFERED);
1108 // a possible error: the table has crashed
1109 $tmp_error = PMA_DBI_getError();
1110 if ($tmp_error) {
1111 return PMA_exportOutputHandler(PMA_exportComment(__('in use') . ' (' . $tmp_error . ')'));
1114 if ($result != false) {
1115 $fields_cnt = PMA_DBI_num_fields($result);
1117 // Get field information
1118 $fields_meta = PMA_DBI_get_fields_meta($result);
1119 $field_flags = array();
1120 for ($j = 0; $j < $fields_cnt; $j++) {
1121 $field_flags[$j] = PMA_DBI_field_flags($result, $j);
1124 for ($j = 0; $j < $fields_cnt; $j++) {
1125 if (isset($analyzed_sql[0]['select_expr'][$j]['column'])) {
1126 $field_set[$j] = PMA_backquote($analyzed_sql[0]['select_expr'][$j]['column'], $sql_backquotes);
1127 } else {
1128 $field_set[$j] = PMA_backquote($fields_meta[$j]->name, $sql_backquotes);
1132 if (isset($GLOBALS['sql_type']) && $GLOBALS['sql_type'] == 'UPDATE') {
1133 // update
1134 $schema_insert = 'UPDATE ';
1135 if (isset($GLOBALS['sql_ignore'])) {
1136 $schema_insert .= 'IGNORE ';
1138 // avoid EOL blank
1139 $schema_insert .= PMA_backquote($table, $sql_backquotes) . ' SET';
1140 } else {
1141 // insert or replace
1142 if (isset($GLOBALS['sql_type']) && $GLOBALS['sql_type'] == 'REPLACE') {
1143 $sql_command = 'REPLACE';
1144 } else {
1145 $sql_command = 'INSERT';
1148 // delayed inserts?
1149 if (isset($GLOBALS['sql_delayed'])) {
1150 $insert_delayed = ' DELAYED';
1151 } else {
1152 $insert_delayed = '';
1155 // insert ignore?
1156 if (isset($GLOBALS['sql_type']) && $GLOBALS['sql_type'] == 'INSERT' && isset($GLOBALS['sql_ignore'])) {
1157 $insert_delayed .= ' IGNORE';
1160 // scheme for inserting fields
1161 if ($GLOBALS['sql_insert_syntax'] == 'complete' || $GLOBALS['sql_insert_syntax'] == 'both') {
1162 $fields = implode(', ', $field_set);
1163 $schema_insert = $sql_command . $insert_delayed .' INTO ' . PMA_backquote($table, $sql_backquotes)
1164 // avoid EOL blank
1165 . ' (' . $fields . ') VALUES';
1166 } else {
1167 $schema_insert = $sql_command . $insert_delayed .' INTO ' . PMA_backquote($table, $sql_backquotes)
1168 . ' VALUES';
1172 $search = array("\x00", "\x0a", "\x0d", "\x1a"); //\x08\\x09, not required
1173 $replace = array('\0', '\n', '\r', '\Z');
1174 $current_row = 0;
1175 $query_size = 0;
1176 if (($GLOBALS['sql_insert_syntax'] == 'extended' || $GLOBALS['sql_insert_syntax'] == 'both') && (!isset($GLOBALS['sql_type']) || $GLOBALS['sql_type'] != 'UPDATE')) {
1177 $separator = ',';
1178 $schema_insert .= $crlf;
1179 } else {
1180 $separator = ';';
1183 while ($row = PMA_DBI_fetch_row($result)) {
1184 if ($current_row == 0) {
1185 $head = PMA_possibleCRLF()
1186 . PMA_exportComment()
1187 . PMA_exportComment(__('Dumping data for table') . ' ' . $formatted_table_name)
1188 . PMA_exportComment()
1189 . $crlf;
1190 if (! PMA_exportOutputHandler($head)) {
1191 return false;
1194 $current_row++;
1195 for ($j = 0; $j < $fields_cnt; $j++) {
1196 // NULL
1197 if (!isset($row[$j]) || is_null($row[$j])) {
1198 $values[] = 'NULL';
1199 // a number
1200 // timestamp is numeric on some MySQL 4.1, BLOBs are sometimes numeric
1201 } elseif ($fields_meta[$j]->numeric && $fields_meta[$j]->type != 'timestamp'
1202 && ! $fields_meta[$j]->blob) {
1203 $values[] = $row[$j];
1204 // a true BLOB
1205 // - mysqldump only generates hex data when the --hex-blob
1206 // option is used, for fields having the binary attribute
1207 // no hex is generated
1208 // - a TEXT field returns type blob but a real blob
1209 // returns also the 'binary' flag
1210 } elseif (stristr($field_flags[$j], 'BINARY')
1211 && $fields_meta[$j]->blob
1212 && isset($GLOBALS['sql_hex_for_blob'])) {
1213 // empty blobs need to be different, but '0' is also empty :-(
1214 if (empty($row[$j]) && $row[$j] != '0') {
1215 $values[] = '\'\'';
1216 } else {
1217 $values[] = '0x' . bin2hex($row[$j]);
1219 // detection of 'bit' works only on mysqli extension
1220 } elseif ($fields_meta[$j]->type == 'bit') {
1221 $values[] = "b'" . PMA_sqlAddSlashes(PMA_printable_bit_value($row[$j], $fields_meta[$j]->length)) . "'";
1222 // something else -> treat as a string
1223 } else {
1224 $values[] = '\'' . str_replace($search, $replace, PMA_sqlAddSlashes($row[$j])) . '\'';
1225 } // end if
1226 } // end for
1228 // should we make update?
1229 if (isset($GLOBALS['sql_type']) && $GLOBALS['sql_type'] == 'UPDATE') {
1231 $insert_line = $schema_insert;
1232 for ($i = 0; $i < $fields_cnt; $i++) {
1233 if (0 == $i) {
1234 $insert_line .= ' ';
1236 if ($i > 0) {
1237 // avoid EOL blank
1238 $insert_line .= ',';
1240 $insert_line .= $field_set[$i] . ' = ' . $values[$i];
1243 list($tmp_unique_condition, $tmp_clause_is_unique) = PMA_getUniqueCondition($result, $fields_cnt, $fields_meta, $row);
1244 $insert_line .= ' WHERE ' . $tmp_unique_condition;
1245 unset($tmp_unique_condition, $tmp_clause_is_unique);
1247 } else {
1249 // Extended inserts case
1250 if ($GLOBALS['sql_insert_syntax'] == 'extended' || $GLOBALS['sql_insert_syntax'] == 'both') {
1251 if ($current_row == 1) {
1252 $insert_line = $schema_insert . '(' . implode(', ', $values) . ')';
1253 } else {
1254 $insert_line = '(' . implode(', ', $values) . ')';
1255 if (isset($GLOBALS['sql_max_query_size']) && $GLOBALS['sql_max_query_size'] > 0 && $query_size + strlen($insert_line) > $GLOBALS['sql_max_query_size']) {
1256 if (!PMA_exportOutputHandler(';' . $crlf)) {
1257 return false;
1259 $query_size = 0;
1260 $current_row = 1;
1261 $insert_line = $schema_insert . $insert_line;
1264 $query_size += strlen($insert_line);
1266 // Other inserts case
1267 else {
1268 $insert_line = $schema_insert . '(' . implode(', ', $values) . ')';
1271 unset($values);
1273 if (!PMA_exportOutputHandler(($current_row == 1 ? '' : $separator . $crlf) . $insert_line)) {
1274 return false;
1277 } // end while
1278 if ($current_row > 0) {
1279 if (!PMA_exportOutputHandler(';' . $crlf)) {
1280 return false;
1283 } // end if ($result != false)
1284 PMA_DBI_free_result($result);
1286 return true;
1287 } // end of the 'PMA_exportData()' function