Merge branch 'master' of ssh://repo.or.cz/srv/git/phpmyadmin/madhuracj into OpenGIS
[phpmyadmin/madhuracj.git] / libraries / export / sql.php
blob21a9eecd91f8973584d8c8f7e6f87ba436135860
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 column names with backquotes <i>(Protects column 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($GLOBALS['sql_backquotes'])) {
314 $GLOBALS['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 columns 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;
711 global $sql_constraints_query; // just the text of the query
712 global $sql_drop_foreign_keys;
714 $schema_create = '';
715 $auto_increment = '';
716 $new_crlf = $crlf;
718 // need to use PMA_DBI_QUERY_STORE with PMA_DBI_num_rows() in mysqli
719 $result = PMA_DBI_query('SHOW TABLE STATUS FROM ' . PMA_backquote($db) . ' LIKE \'' . PMA_sqlAddSlashes($table, true) . '\'', null, PMA_DBI_QUERY_STORE);
720 if ($result != false) {
721 if (PMA_DBI_num_rows($result) > 0) {
722 $tmpres = PMA_DBI_fetch_assoc($result);
723 if (PMA_DRIZZLE && $show_dates) {
724 // Drizzle doesn't give Create_time and Update_time in SHOW TABLE STATUS, add it
725 $sql ="SELECT
726 TABLE_CREATION_TIME AS Create_time,
727 TABLE_UPDATE_TIME AS Update_time
728 FROM data_dictionary.TABLES
729 WHERE TABLE_SCHEMA = '" . PMA_sqlAddSlashes($db) . "'
730 AND TABLE_NAME = '" . PMA_sqlAddSlashes($table) . "'";
731 $tmpres = array_merge(PMA_DBI_fetch_single_row($sql), $tmpres);
733 // Here we optionally add the AUTO_INCREMENT next value,
734 // but starting with MySQL 5.0.24, the clause is already included
735 // in SHOW CREATE TABLE so we'll remove it below
736 // It's required for Drizzle because SHOW CREATE TABLE uses
737 // the value from table's creation time
738 if (isset($GLOBALS['sql_auto_increment']) && !empty($tmpres['Auto_increment'])) {
739 $auto_increment .= ' AUTO_INCREMENT=' . $tmpres['Auto_increment'] . ' ';
742 if ($show_dates && isset($tmpres['Create_time']) && !empty($tmpres['Create_time'])) {
743 $schema_create .= PMA_exportComment(__('Creation') . ': ' . PMA_localisedDate(strtotime($tmpres['Create_time'])));
744 $new_crlf = PMA_exportComment() . $crlf;
747 if ($show_dates && isset($tmpres['Update_time']) && !empty($tmpres['Update_time'])) {
748 $schema_create .= PMA_exportComment(__('Last update') . ': ' . PMA_localisedDate(strtotime($tmpres['Update_time'])));
749 $new_crlf = PMA_exportComment() . $crlf;
752 if ($show_dates && isset($tmpres['Check_time']) && !empty($tmpres['Check_time'])) {
753 $schema_create .= PMA_exportComment(__('Last check') . ': ' . PMA_localisedDate(strtotime($tmpres['Check_time'])));
754 $new_crlf = PMA_exportComment() . $crlf;
757 PMA_DBI_free_result($result);
760 $schema_create .= $new_crlf;
762 // no need to generate a DROP VIEW here, it was done earlier
763 if (! empty($sql_drop_table) && ! PMA_Table::isView($db, $table)) {
764 $schema_create .= 'DROP TABLE IF EXISTS ' . PMA_backquote($table, $sql_backquotes) . ';' . $crlf;
767 // Complete table dump,
768 // Whether to quote table and column names or not
769 // Drizzle always quotes names
770 if (!PMA_DRIZZLE) {
771 if ($sql_backquotes) {
772 PMA_DBI_query('SET SQL_QUOTE_SHOW_CREATE = 1');
773 } else {
774 PMA_DBI_query('SET SQL_QUOTE_SHOW_CREATE = 0');
778 // I don't see the reason why this unbuffered query could cause problems,
779 // because SHOW CREATE TABLE returns only one row, and we free the
780 // results below. Nonetheless, we got 2 user reports about this
781 // (see bug 1562533) so I remove the unbuffered mode.
782 //$result = PMA_DBI_query('SHOW CREATE TABLE ' . PMA_backquote($db) . '.' . PMA_backquote($table), null, PMA_DBI_QUERY_UNBUFFERED);
784 // Note: SHOW CREATE TABLE, at least in MySQL 5.1.23, does not
785 // produce a displayable result for the default value of a BIT
786 // column, nor does the mysqldump command. See MySQL bug 35796
787 $result = PMA_DBI_try_query('SHOW CREATE TABLE ' . PMA_backquote($db) . '.' . PMA_backquote($table));
788 // an error can happen, for example the table is crashed
789 $tmp_error = PMA_DBI_getError();
790 if ($tmp_error) {
791 return PMA_exportComment(__('in use') . '(' . $tmp_error . ')');
794 if ($result != false && ($row = PMA_DBI_fetch_row($result))) {
795 $create_query = $row[1];
796 unset($row);
798 // Convert end of line chars to one that we want (note that MySQL doesn't return query it will accept in all cases)
799 if (strpos($create_query, "(\r\n ")) {
800 $create_query = str_replace("\r\n", $crlf, $create_query);
801 } elseif (strpos($create_query, "(\n ")) {
802 $create_query = str_replace("\n", $crlf, $create_query);
803 } elseif (strpos($create_query, "(\r ")) {
804 $create_query = str_replace("\r", $crlf, $create_query);
808 * Drop database name from VIEW creation.
810 * This is a bit tricky, but we need to issue SHOW CREATE TABLE with
811 * database name, but we don't want name to show up in CREATE VIEW
812 * statement.
814 if ($view) {
815 $create_query = preg_replace('/' . PMA_backquote($db) . '\./', '', $create_query);
818 // Should we use IF NOT EXISTS?
819 if (isset($GLOBALS['sql_if_not_exists'])) {
820 $create_query = preg_replace('/^CREATE TABLE/', 'CREATE TABLE IF NOT EXISTS', $create_query);
823 // Drizzle (checked on 2011.03.13) returns ROW_FORMAT surrounded with quotes, which is not accepted by parser
824 if (PMA_DRIZZLE) {
825 $create_query = preg_replace('/ROW_FORMAT=\'(\S+)\'/', 'ROW_FORMAT=$1', $create_query);
828 // are there any constraints to cut out?
829 if (preg_match('@CONSTRAINT|FOREIGN[\s]+KEY@', $create_query)) {
831 // Split the query into lines, so we can easily handle it. We know lines are separated by $crlf (done few lines above).
832 $sql_lines = explode($crlf, $create_query);
833 $sql_count = count($sql_lines);
835 // lets find first line with constraints
836 for ($i = 0; $i < $sql_count; $i++) {
837 if (preg_match('@^[\s]*(CONSTRAINT|FOREIGN[\s]+KEY)@', $sql_lines[$i])) {
838 break;
842 // If we really found a constraint
843 if ($i != $sql_count) {
845 // remove , from the end of create statement
846 $sql_lines[$i - 1] = preg_replace('@,$@', '', $sql_lines[$i - 1]);
848 // prepare variable for constraints
849 if (!isset($sql_constraints)) {
850 if (isset($GLOBALS['no_constraints_comments'])) {
851 $sql_constraints = '';
852 } else {
853 $sql_constraints = $crlf
854 . PMA_exportComment()
855 . PMA_exportComment(__('Constraints for dumped tables'))
856 . PMA_exportComment();
860 // comments for current table
861 if (!isset($GLOBALS['no_constraints_comments'])) {
862 $sql_constraints .= $crlf
863 . PMA_exportComment()
864 . PMA_exportComment(__('Constraints for table') . ' ' . PMA_backquote($table))
865 . PMA_exportComment();
868 // let's do the work
869 $sql_constraints_query .= 'ALTER TABLE ' . PMA_backquote($table) . $crlf;
870 $sql_constraints .= 'ALTER TABLE ' . PMA_backquote($table) . $crlf;
871 $sql_drop_foreign_keys .= 'ALTER TABLE ' . PMA_backquote($db) . '.' . PMA_backquote($table) . $crlf;
873 $first = true;
874 for ($j = $i; $j < $sql_count; $j++) {
875 if (preg_match('@CONSTRAINT|FOREIGN[\s]+KEY@', $sql_lines[$j])) {
876 if (!$first) {
877 $sql_constraints .= $crlf;
879 if (strpos($sql_lines[$j], 'CONSTRAINT') === false) {
880 $tmp_str = preg_replace('/(FOREIGN[\s]+KEY)/', 'ADD \1', $sql_lines[$j]);
881 $sql_constraints_query .= $tmp_str;
882 $sql_constraints .= $tmp_str;
883 } else {
884 $tmp_str = preg_replace('/(CONSTRAINT)/', 'ADD \1', $sql_lines[$j]);
885 $sql_constraints_query .= $tmp_str;
886 $sql_constraints .= $tmp_str;
887 preg_match('/(CONSTRAINT)([\s])([\S]*)([\s])/', $sql_lines[$j], $matches);
888 if (! $first) {
889 $sql_drop_foreign_keys .= ', ';
891 $sql_drop_foreign_keys .= 'DROP FOREIGN KEY ' . $matches[3];
893 $first = false;
894 } else {
895 break;
898 $sql_constraints .= ';' . $crlf;
899 $sql_constraints_query .= ';';
901 $create_query = implode($crlf, array_slice($sql_lines, 0, $i)) . $crlf . implode($crlf, array_slice($sql_lines, $j, $sql_count - 1));
902 unset($sql_lines);
905 $schema_create .= $create_query;
908 // remove a possible "AUTO_INCREMENT = value" clause
909 // that could be there starting with MySQL 5.0.24
910 // in Drizzle it's useless as it contains the value given at table creation time
911 $schema_create = preg_replace('/AUTO_INCREMENT\s*=\s*([0-9])+/', '', $schema_create);
913 $schema_create .= $auto_increment;
915 PMA_DBI_free_result($result);
916 return $schema_create . ($add_semicolon ? ';' . $crlf : '');
917 } // end of the 'PMA_getTableDef()' function
920 * Returns $table's comments, relations etc.
922 * @param string $db database name
923 * @param string $table table name
924 * @param string $crlf end of line sequence
925 * @param bool $do_relation whether to include relation comments
926 * @param bool $do_mime whether to include mime comments
927 * @return string resulting comments
929 * @access private
931 function PMA_getTableComments($db, $table, $crlf, $do_relation = false, $do_mime = false)
933 global $cfgRelation;
934 global $sql_backquotes;
935 global $sql_constraints;
937 $schema_create = '';
939 // Check if we can use Relations
940 if ($do_relation && !empty($cfgRelation['relation'])) {
941 // Find which tables are related with the current one and write it in
942 // an array
943 $res_rel = PMA_getForeigners($db, $table);
945 if ($res_rel && count($res_rel) > 0) {
946 $have_rel = true;
947 } else {
948 $have_rel = false;
950 } else {
951 $have_rel = false;
952 } // end if
954 if ($do_mime && $cfgRelation['mimework']) {
955 if (!($mime_map = PMA_getMIME($db, $table, true))) {
956 unset($mime_map);
960 if (isset($mime_map) && count($mime_map) > 0) {
961 $schema_create .= PMA_possibleCRLF()
962 . PMA_exportComment()
963 . PMA_exportComment(__('MIME TYPES FOR TABLE'). ' ' . PMA_backquote($table, $sql_backquotes) . ':');
964 @reset($mime_map);
965 foreach ($mime_map AS $mime_field => $mime) {
966 $schema_create .= PMA_exportComment(' ' . PMA_backquote($mime_field, $sql_backquotes))
967 . PMA_exportComment(' ' . PMA_backquote($mime['mimetype'], $sql_backquotes));
969 $schema_create .= PMA_exportComment();
972 if ($have_rel) {
973 $schema_create .= PMA_possibleCRLF()
974 . PMA_exportComment()
975 . PMA_exportComment(__('RELATIONS FOR TABLE'). ' ' . PMA_backquote($table, $sql_backquotes) . ':');
976 foreach ($res_rel AS $rel_field => $rel) {
977 $schema_create .= PMA_exportComment(' ' . PMA_backquote($rel_field, $sql_backquotes))
978 . PMA_exportComment(' ' . PMA_backquote($rel['foreign_table'], $sql_backquotes)
979 . ' -> ' . PMA_backquote($rel['foreign_field'], $sql_backquotes));
981 $schema_create .= PMA_exportComment();
984 return $schema_create;
986 } // end of the 'PMA_getTableComments()' function
989 * Outputs table's structure
991 * @param string $db database name
992 * @param string $table table name
993 * @param string $crlf the end of line sequence
994 * @param string $error_url the url to go back in case of error
995 * @param bool $relation whether to include relation comments
996 * @param bool $comments whether to include the pmadb-style column comments
997 * as comments in the structure; this is deprecated
998 * but the parameter is left here because export.php
999 * calls PMA_exportStructure() also for other export
1000 * types which use this parameter
1001 * @param bool $mime whether to include mime comments
1002 * @param bool $dates whether to include creation/update/check dates
1003 * @param string $export_mode 'create_table', 'triggers', 'create_view', 'stand_in'
1004 * @param string $export_type 'server', 'database', 'table'
1005 * @return bool Whether it suceeded
1007 * @access public
1009 function PMA_exportStructure($db, $table, $crlf, $error_url, $relation = false, $comments = false, $mime = false, $dates = false, $export_mode, $export_type)
1011 $formatted_table_name = (isset($GLOBALS['sql_backquotes']))
1012 ? PMA_backquote($table)
1013 : '\'' . $table . '\'';
1014 $dump = PMA_possibleCRLF()
1015 . PMA_exportComment(str_repeat('-', 56))
1016 . PMA_possibleCRLF()
1017 . PMA_exportComment();
1019 switch($export_mode) {
1020 case 'create_table':
1021 $dump .= PMA_exportComment(__('Table structure for table') . ' ' . $formatted_table_name);
1022 $dump .= PMA_exportComment();
1023 $dump .= PMA_getTableDef($db, $table, $crlf, $error_url, $dates);
1024 $dump .= PMA_getTableComments($db, $table, $crlf, $relation, $mime);
1025 break;
1026 case 'triggers':
1027 $dump = '';
1028 $triggers = PMA_DBI_get_triggers($db, $table);
1029 if ($triggers) {
1030 $dump .= PMA_possibleCRLF()
1031 . PMA_exportComment()
1032 . PMA_exportComment(__('Triggers') . ' ' . $formatted_table_name)
1033 . PMA_exportComment();
1034 $delimiter = '//';
1035 foreach ($triggers as $trigger) {
1036 $dump .= $trigger['drop'] . ';' . $crlf;
1037 $dump .= 'DELIMITER ' . $delimiter . $crlf;
1038 $dump .= $trigger['create'];
1039 $dump .= 'DELIMITER ;' . $crlf;
1042 break;
1043 case 'create_view':
1044 $dump .= PMA_exportComment(__('Structure for view') . ' ' . $formatted_table_name)
1045 . PMA_exportComment();
1046 // delete the stand-in table previously created (if any)
1047 if ($export_type != 'table') {
1048 $dump .= 'DROP TABLE IF EXISTS ' . PMA_backquote($table) . ';' . $crlf;
1050 $dump .= PMA_getTableDef($db, $table, $crlf, $error_url, $dates, true, true);
1051 break;
1052 case 'stand_in':
1053 $dump .= PMA_exportComment(__('Stand-in structure for view') . ' ' . $formatted_table_name)
1054 . PMA_exportComment();
1055 // export a stand-in definition to resolve view dependencies
1056 $dump .= PMA_getTableDefStandIn($db, $table, $crlf);
1057 } // end switch
1059 // this one is built by PMA_getTableDef() to use in table copy/move
1060 // but not in the case of export
1061 unset($GLOBALS['sql_constraints_query']);
1063 return PMA_exportOutputHandler($dump);
1067 * Outputs the content of a table in SQL format
1069 * @param string $db database name
1070 * @param string $table table name
1071 * @param string $crlf the end of line sequence
1072 * @param string $error_url the url to go back in case of error
1073 * @param string $sql_query SQL query for obtaining data
1074 * @return bool Whether it suceeded
1076 * @access public
1078 function PMA_exportData($db, $table, $crlf, $error_url, $sql_query)
1080 global $sql_backquotes;
1081 global $current_row;
1083 $formatted_table_name = (isset($GLOBALS['sql_backquotes']))
1084 ? PMA_backquote($table)
1085 : '\'' . $table . '\'';
1087 // Do not export data for a VIEW
1088 // (For a VIEW, this is called only when exporting a single VIEW)
1089 if (PMA_Table::isView($db, $table)) {
1090 $head = PMA_possibleCRLF()
1091 . PMA_exportComment()
1092 . PMA_exportComment('VIEW ' . ' ' . $formatted_table_name)
1093 . PMA_exportComment(__('Data') . ': ' . __('None'))
1094 . PMA_exportComment()
1095 . PMA_possibleCRLF();
1097 if (! PMA_exportOutputHandler($head)) {
1098 return false;
1100 return true;
1103 // analyze the query to get the true column names, not the aliases
1104 // (this fixes an undefined index, also if Complete inserts
1105 // are used, we did not get the true column name in case of aliases)
1106 $analyzed_sql = PMA_SQP_analyze(PMA_SQP_parse($sql_query));
1108 $result = PMA_DBI_try_query($sql_query, null, PMA_DBI_QUERY_UNBUFFERED);
1109 // a possible error: the table has crashed
1110 $tmp_error = PMA_DBI_getError();
1111 if ($tmp_error) {
1112 return PMA_exportOutputHandler(PMA_exportComment(__('Error reading data:') . ' (' . $tmp_error . ')'));
1115 if ($result != false) {
1116 $fields_cnt = PMA_DBI_num_fields($result);
1118 // Get field information
1119 $fields_meta = PMA_DBI_get_fields_meta($result);
1120 $field_flags = array();
1121 for ($j = 0; $j < $fields_cnt; $j++) {
1122 $field_flags[$j] = PMA_DBI_field_flags($result, $j);
1125 for ($j = 0; $j < $fields_cnt; $j++) {
1126 if (isset($analyzed_sql[0]['select_expr'][$j]['column'])) {
1127 $field_set[$j] = PMA_backquote($analyzed_sql[0]['select_expr'][$j]['column'], $sql_backquotes);
1128 } else {
1129 $field_set[$j] = PMA_backquote($fields_meta[$j]->name, $sql_backquotes);
1133 if (isset($GLOBALS['sql_type']) && $GLOBALS['sql_type'] == 'UPDATE') {
1134 // update
1135 $schema_insert = 'UPDATE ';
1136 if (isset($GLOBALS['sql_ignore'])) {
1137 $schema_insert .= 'IGNORE ';
1139 // avoid EOL blank
1140 $schema_insert .= PMA_backquote($table, $sql_backquotes) . ' SET';
1141 } else {
1142 // insert or replace
1143 if (isset($GLOBALS['sql_type']) && $GLOBALS['sql_type'] == 'REPLACE') {
1144 $sql_command = 'REPLACE';
1145 } else {
1146 $sql_command = 'INSERT';
1149 // delayed inserts?
1150 if (isset($GLOBALS['sql_delayed'])) {
1151 $insert_delayed = ' DELAYED';
1152 } else {
1153 $insert_delayed = '';
1156 // insert ignore?
1157 if (isset($GLOBALS['sql_type']) && $GLOBALS['sql_type'] == 'INSERT' && isset($GLOBALS['sql_ignore'])) {
1158 $insert_delayed .= ' IGNORE';
1161 // scheme for inserting fields
1162 if ($GLOBALS['sql_insert_syntax'] == 'complete' || $GLOBALS['sql_insert_syntax'] == 'both') {
1163 $fields = implode(', ', $field_set);
1164 $schema_insert = $sql_command . $insert_delayed .' INTO ' . PMA_backquote($table, $sql_backquotes)
1165 // avoid EOL blank
1166 . ' (' . $fields . ') VALUES';
1167 } else {
1168 $schema_insert = $sql_command . $insert_delayed .' INTO ' . PMA_backquote($table, $sql_backquotes)
1169 . ' VALUES';
1173 $search = array("\x00", "\x0a", "\x0d", "\x1a"); //\x08\\x09, not required
1174 $replace = array('\0', '\n', '\r', '\Z');
1175 $current_row = 0;
1176 $query_size = 0;
1177 if (($GLOBALS['sql_insert_syntax'] == 'extended' || $GLOBALS['sql_insert_syntax'] == 'both') && (!isset($GLOBALS['sql_type']) || $GLOBALS['sql_type'] != 'UPDATE')) {
1178 $separator = ',';
1179 $schema_insert .= $crlf;
1180 } else {
1181 $separator = ';';
1184 while ($row = PMA_DBI_fetch_row($result)) {
1185 if ($current_row == 0) {
1186 $head = PMA_possibleCRLF()
1187 . PMA_exportComment()
1188 . PMA_exportComment(__('Dumping data for table') . ' ' . $formatted_table_name)
1189 . PMA_exportComment()
1190 . $crlf;
1191 if (! PMA_exportOutputHandler($head)) {
1192 return false;
1195 $current_row++;
1196 for ($j = 0; $j < $fields_cnt; $j++) {
1197 // NULL
1198 if (!isset($row[$j]) || is_null($row[$j])) {
1199 $values[] = 'NULL';
1200 // a number
1201 // timestamp is numeric on some MySQL 4.1, BLOBs are sometimes numeric
1202 } elseif ($fields_meta[$j]->numeric && $fields_meta[$j]->type != 'timestamp'
1203 && ! $fields_meta[$j]->blob) {
1204 $values[] = $row[$j];
1205 // a true BLOB
1206 // - mysqldump only generates hex data when the --hex-blob
1207 // option is used, for fields having the binary attribute
1208 // no hex is generated
1209 // - a TEXT field returns type blob but a real blob
1210 // returns also the 'binary' flag
1211 } elseif (stristr($field_flags[$j], 'BINARY')
1212 && $fields_meta[$j]->blob
1213 && isset($GLOBALS['sql_hex_for_blob'])) {
1214 // empty blobs need to be different, but '0' is also empty :-(
1215 if (empty($row[$j]) && $row[$j] != '0') {
1216 $values[] = '\'\'';
1217 } else {
1218 $values[] = '0x' . bin2hex($row[$j]);
1220 // detection of 'bit' works only on mysqli extension
1221 } elseif ($fields_meta[$j]->type == 'bit') {
1222 $values[] = "b'" . PMA_sqlAddSlashes(PMA_printable_bit_value($row[$j], $fields_meta[$j]->length)) . "'";
1223 // something else -> treat as a string
1224 } else {
1225 $values[] = '\'' . str_replace($search, $replace, PMA_sqlAddSlashes($row[$j])) . '\'';
1226 } // end if
1227 } // end for
1229 // should we make update?
1230 if (isset($GLOBALS['sql_type']) && $GLOBALS['sql_type'] == 'UPDATE') {
1232 $insert_line = $schema_insert;
1233 for ($i = 0; $i < $fields_cnt; $i++) {
1234 if (0 == $i) {
1235 $insert_line .= ' ';
1237 if ($i > 0) {
1238 // avoid EOL blank
1239 $insert_line .= ',';
1241 $insert_line .= $field_set[$i] . ' = ' . $values[$i];
1244 list($tmp_unique_condition, $tmp_clause_is_unique) = PMA_getUniqueCondition($result, $fields_cnt, $fields_meta, $row);
1245 $insert_line .= ' WHERE ' . $tmp_unique_condition;
1246 unset($tmp_unique_condition, $tmp_clause_is_unique);
1248 } else {
1250 // Extended inserts case
1251 if ($GLOBALS['sql_insert_syntax'] == 'extended' || $GLOBALS['sql_insert_syntax'] == 'both') {
1252 if ($current_row == 1) {
1253 $insert_line = $schema_insert . '(' . implode(', ', $values) . ')';
1254 } else {
1255 $insert_line = '(' . implode(', ', $values) . ')';
1256 if (isset($GLOBALS['sql_max_query_size']) && $GLOBALS['sql_max_query_size'] > 0 && $query_size + strlen($insert_line) > $GLOBALS['sql_max_query_size']) {
1257 if (!PMA_exportOutputHandler(';' . $crlf)) {
1258 return false;
1260 $query_size = 0;
1261 $current_row = 1;
1262 $insert_line = $schema_insert . $insert_line;
1265 $query_size += strlen($insert_line);
1267 // Other inserts case
1268 else {
1269 $insert_line = $schema_insert . '(' . implode(', ', $values) . ')';
1272 unset($values);
1274 if (!PMA_exportOutputHandler(($current_row == 1 ? '' : $separator . $crlf) . $insert_line)) {
1275 return false;
1278 } // end while
1279 if ($current_row > 0) {
1280 if (!PMA_exportOutputHandler(';' . $crlf)) {
1281 return false;
1284 } // end if ($result != false)
1285 PMA_DBI_free_result($result);
1287 return true;
1288 } // end of the 'PMA_exportData()' function