Translated using Weblate (Turkish)
[phpmyadmin.git] / libraries / export.lib.php
blob3ed20a4fb1a78bc60505293228ded39bee887df1
1 <?php
3 /* vim: set expandtab sw=4 ts=4 sts=4: */
4 /**
5 * function for the main export logic
7 * @package PhpMyAdmin
8 */
10 if (! defined('PHPMYADMIN')) {
11 exit;
14 /**
15 * Sets a session variable upon a possible fatal error during export
17 * @return void
19 function PMA_shutdownDuringExport()
21 $a = error_get_last();
22 if ($a != null && strpos($a['message'], "execution time")) {
23 //write in partially downloaded file for future reference of user
24 print_r($a);
25 //set session variable to check if there was error while exporting
26 $_SESSION['pma_export_error'] = $a['message'];
30 /**
31 * Detect ob_gzhandler
33 * @return bool
35 function PMA_isGzHandlerEnabled()
37 return in_array('ob_gzhandler', ob_list_handlers());
40 /**
41 * Detect whether gzencode is needed; it might not be needed if
42 * the server is already compressing by itself
44 * @return bool Whether gzencode is needed
46 function PMA_gzencodeNeeded()
49 * We should gzencode only if the function exists
50 * but we don't want to compress twice, therefore
51 * gzencode only if transparent compression is not enabled
52 * and gz compression was not asked via $cfg['OBGzip']
53 * but transparent compression does not apply when saving to server
55 if (@function_exists('gzencode')
56 && ((! @ini_get('zlib.output_compression')
57 && ! PMA_isGzHandlerEnabled())
58 || $GLOBALS['save_on_server'])
59 ) {
60 return true;
61 } else {
62 return false;
66 /**
67 * Output handler for all exports, if needed buffering, it stores data into
68 * $dump_buffer, otherwise it prints them out.
70 * @param string $line the insert statement
72 * @return bool Whether output succeeded
74 function PMA_exportOutputHandler($line)
76 global $time_start, $dump_buffer, $dump_buffer_len, $save_filename;
78 // Kanji encoding convert feature
79 if ($GLOBALS['output_kanji_conversion']) {
80 $line = PMA_Kanji_strConv(
81 $line,
82 $GLOBALS['knjenc'],
83 isset($GLOBALS['xkana']) ? $GLOBALS['xkana'] : ''
86 // If we have to buffer data, we will perform everything at once at the end
87 if ($GLOBALS['buffer_needed']) {
89 $dump_buffer .= $line;
90 if ($GLOBALS['onfly_compression']) {
92 $dump_buffer_len += strlen($line);
94 if ($dump_buffer_len > $GLOBALS['memory_limit']) {
95 if ($GLOBALS['output_charset_conversion']) {
96 $dump_buffer = PMA_convertString(
97 'utf-8',
98 $GLOBALS['charset_of_file'],
99 $dump_buffer
102 if ($GLOBALS['compression'] == 'gzip'
103 && PMA_gzencodeNeeded()
105 // as a gzipped file
106 // without the optional parameter level because it bugs
107 $dump_buffer = gzencode($dump_buffer);
109 if ($GLOBALS['save_on_server']) {
110 $write_result = @fwrite($GLOBALS['file_handle'], $dump_buffer);
111 if ($write_result != strlen($dump_buffer)) {
112 $GLOBALS['message'] = PMA_Message::error(
113 __('Insufficient space to save the file %s.')
115 $GLOBALS['message']->addParam($save_filename);
116 return false;
118 } else {
119 echo $dump_buffer;
121 $dump_buffer = '';
122 $dump_buffer_len = 0;
124 } else {
125 $time_now = time();
126 if ($time_start >= $time_now + 30) {
127 $time_start = $time_now;
128 header('X-pmaPing: Pong');
129 } // end if
131 } else {
132 if ($GLOBALS['asfile']) {
133 if ($GLOBALS['output_charset_conversion']) {
134 $line = PMA_convertString(
135 'utf-8',
136 $GLOBALS['charset_of_file'],
137 $line
140 if ($GLOBALS['save_on_server'] && strlen($line) > 0) {
141 $write_result = @fwrite($GLOBALS['file_handle'], $line);
142 if (! $write_result || ($write_result != strlen($line))) {
143 $GLOBALS['message'] = PMA_Message::error(
144 __('Insufficient space to save the file %s.')
146 $GLOBALS['message']->addParam($save_filename);
147 return false;
149 $time_now = time();
150 if ($time_start >= $time_now + 30) {
151 $time_start = $time_now;
152 header('X-pmaPing: Pong');
153 } // end if
154 } else {
155 // We export as file - output normally
156 echo $line;
158 } else {
159 // We export as html - replace special chars
160 echo htmlspecialchars($line);
163 return true;
164 } // end of the 'PMA_exportOutputHandler()' function
167 * Returns HTML containing the footer for a displayed export
169 * @param string $back_button the link for going Back
171 * @return string $html the HTML output
173 function PMA_getHtmlForDisplayedExportFooter($back_button)
176 * Close the html tags and add the footers for on-screen export
178 $html = '</textarea>'
179 . ' </form>'
180 // bottom back button
181 . $back_button
182 . '</div>'
183 . '<script type="text/javascript">' . "\n"
184 . '//<![CDATA[' . "\n"
185 . 'var $body = $("body");' . "\n"
186 . '$("#textSQLDUMP")' . "\n"
187 . '.width($body.width() - 50)' . "\n"
188 . '.height($body.height() - 100);' . "\n"
189 . '//]]>' . "\n"
190 . '</script>' . "\n";
191 return $html;
195 * Computes the memory limit for export
197 * @return int $memory_limit the memory limit
199 function PMA_getMemoryLimitForExport()
201 $memory_limit = trim(@ini_get('memory_limit'));
202 $memory_limit_num = (int)substr($memory_limit, 0, -1);
203 // 2 MB as default
204 if (empty($memory_limit) || '-1' == $memory_limit) {
205 $memory_limit = 2 * 1024 * 1024;
206 } elseif (strtolower(substr($memory_limit, -1)) == 'm') {
207 $memory_limit = $memory_limit_num * 1024 * 1024;
208 } elseif (strtolower(substr($memory_limit, -1)) == 'k') {
209 $memory_limit = $memory_limit_num * 1024;
210 } elseif (strtolower(substr($memory_limit, -1)) == 'g') {
211 $memory_limit = $memory_limit_num * 1024 * 1024 * 1024;
212 } else {
213 $memory_limit = (int)$memory_limit;
216 // Some of memory is needed for other things and as threshold.
217 // During export I had allocated (see memory_get_usage function)
218 // approx 1.2MB so this comes from that.
219 if ($memory_limit > 1500000) {
220 $memory_limit -= 1500000;
223 // Some memory is needed for compression, assume 1/3
224 $memory_limit /= 8;
225 return $memory_limit;
229 * Return the filename and MIME type for export file
231 * @param string $export_type type of export
232 * @param string $remember_template whether to remember template
233 * @param object $export_plugin the export plugin
234 * @param string $compression compression asked
235 * @param string $filename_template the filename template
237 * @return array the filename template and mime type
239 function PMA_getExportFilenameAndMimetype(
240 $export_type, $remember_template, $export_plugin, $compression,
241 $filename_template
243 if ($export_type == 'server') {
244 if (! empty($remember_template)) {
245 $GLOBALS['PMA_Config']->setUserValue(
246 'pma_server_filename_template',
247 'Export/file_template_server',
248 $filename_template
251 } elseif ($export_type == 'database') {
252 if (! empty($remember_template)) {
253 $GLOBALS['PMA_Config']->setUserValue(
254 'pma_db_filename_template',
255 'Export/file_template_database',
256 $filename_template
259 } else {
260 if (! empty($remember_template)) {
261 $GLOBALS['PMA_Config']->setUserValue(
262 'pma_table_filename_template',
263 'Export/file_template_table',
264 $filename_template
268 $filename = PMA_Util::expandUserString($filename_template);
269 // remove dots in filename (coming from either the template or already
270 // part of the filename) to avoid a remote code execution vulnerability
271 $filename = PMA_sanitizeFilename($filename, $replaceDots = true);
273 // Grab basic dump extension and mime type
274 // Check if the user already added extension;
275 // get the substring where the extension would be if it was included
276 $extension_start_pos = strlen($filename) - strlen(
277 $export_plugin->getProperties()->getExtension()
278 ) - 1;
279 $user_extension = substr($filename, $extension_start_pos, strlen($filename));
280 $required_extension = "." . $export_plugin->getProperties()->getExtension();
281 if (strtolower($user_extension) != $required_extension) {
282 $filename .= $required_extension;
284 $mime_type = $export_plugin->getProperties()->getMimeType();
286 // If dump is going to be compressed, set correct mime_type and add
287 // compression to extension
288 if ($compression == 'gzip') {
289 $filename .= '.gz';
290 $mime_type = 'application/x-gzip';
291 } elseif ($compression == 'zip') {
292 $filename .= '.zip';
293 $mime_type = 'application/zip';
295 return array($filename, $mime_type);
299 * Open the export file
301 * @param string $filename the export filename
302 * @param boolean $quick_export whether it's a quick export or not
304 * @return array the full save filename, possible message and the file handle
306 function PMA_openExportFile($filename, $quick_export)
308 $file_handle = null;
309 $message = '';
311 $save_filename = PMA_Util::userDir($GLOBALS['cfg']['SaveDir'])
312 . preg_replace('@[/\\\\]@', '_', $filename);
314 if (file_exists($save_filename)
315 && ((! $quick_export && empty($_REQUEST['onserverover']))
316 || ($quick_export
317 && $_REQUEST['quick_export_onserverover'] != 'saveitover'))
319 $message = PMA_Message::error(
321 'File %s already exists on server, '
322 . 'change filename or check overwrite option.'
325 $message->addParam($save_filename);
326 } elseif (is_file($save_filename) && ! is_writable($save_filename)) {
327 $message = PMA_Message::error(
329 'The web server does not have permission '
330 . 'to save the file %s.'
333 $message->addParam($save_filename);
334 } elseif (! $file_handle = @fopen($save_filename, 'w')) {
335 $message = PMA_Message::error(
337 'The web server does not have permission '
338 . 'to save the file %s.'
341 $message->addParam($save_filename);
343 return array($save_filename, $message, $file_handle);
347 * Close the export file
349 * @param resource $file_handle the export file handle
350 * @param string $dump_buffer the current dump buffer
351 * @param string $save_filename the export filename
353 * @return object $message a message object (or empty string)
355 function PMA_closeExportFile($file_handle, $dump_buffer, $save_filename)
357 $write_result = @fwrite($file_handle, $dump_buffer);
358 fclose($file_handle);
359 if (strlen($dump_buffer) > 0
360 && (! $write_result || ($write_result != strlen($dump_buffer)))
362 $message = new PMA_Message(
363 __('Insufficient space to save the file %s.'),
364 PMA_Message::ERROR,
365 array($save_filename)
367 } else {
368 $message = new PMA_Message(
369 __('Dump has been saved to file %s.'),
370 PMA_Message::SUCCESS,
371 array($save_filename)
374 return $message;
378 * Compress the export buffer
380 * @param string $dump_buffer the current dump buffer
381 * @param string $compression the compression mode
382 * @param string $filename the filename
384 * @return object $message a message object (or empty string)
386 function PMA_compressExport($dump_buffer, $compression, $filename)
388 if ($compression == 'zip' && @function_exists('gzcompress')) {
389 $zipfile = new ZipFile();
390 $zipfile->addFile($dump_buffer, substr($filename, 0, -4));
391 $dump_buffer = $zipfile->file();
392 } elseif ($compression == 'gzip' && PMA_gzencodeNeeded()) {
393 // without the optional parameter level because it bugs
394 $dump_buffer = gzencode($dump_buffer);
396 return $dump_buffer;
400 * Returns HTML containing the header for a displayed export
402 * @param string $export_type the export type
403 * @param string $db the database name
404 * @param string $table the table name
406 * @return array the generated HTML and back button
408 function PMA_getHtmlForDisplayedExportHeader($export_type, $db, $table)
410 $html = '<div style="text-align: ' . $GLOBALS['cell_align_left'] . '">';
413 * Displays a back button with all the $_REQUEST data in the URL
414 * (store in a variable to also display after the textarea)
416 $back_button = '<p>[ <a href="';
417 if ($export_type == 'server') {
418 $back_button .= 'server_export.php?' . PMA_URL_getCommon();
419 } elseif ($export_type == 'database') {
420 $back_button .= 'db_export.php?' . PMA_URL_getCommon($db);
421 } else {
422 $back_button .= 'tbl_export.php?' . PMA_URL_getCommon($db, $table);
425 // Convert the multiple select elements from an array to a string
426 if ($export_type == 'server' && isset($_REQUEST['db_select'])) {
427 $_REQUEST['db_select'] = implode(",", $_REQUEST['db_select']);
428 } elseif ($export_type == 'database'
429 && isset($_REQUEST['table_select'])
431 $_REQUEST['table_select'] = implode(",", $_REQUEST['table_select']);
434 foreach ($_REQUEST as $name => $value) {
435 if (!is_array($value)) {
436 $back_button .= '&amp;' . urlencode($name) . '=' . urlencode($value);
439 $back_button .= '&amp;repopulate=1">' . __('Back') . '</a> ]</p>';
441 $html .= $back_button
442 . '<form name="nofunction">'
443 . '<textarea name="sqldump" cols="50" rows="30" '
444 . 'id="textSQLDUMP" wrap="OFF">';
446 return array($html, $back_button);
450 * Export at the server level
452 * @param string $db_select the selected databases to export
453 * @param string $whatStrucOrData structure or data or both
454 * @param object $export_plugin the selected export plugin
455 * @param string $crlf end of line character(s)
456 * @param string $err_url the URL in case of error
457 * @param string $export_type the export type
458 * @param bool $do_relation whether to export relation info
459 * @param bool $do_comments whether to add comments
460 * @param bool $do_mime whether to add MIME info
461 * @param bool $do_dates whether to add dates
462 * @param array $aliases Alias information for db/table/column
464 * @return void
466 function PMA_exportServer(
467 $db_select, $whatStrucOrData, $export_plugin, $crlf, $err_url,
468 $export_type, $do_relation, $do_comments, $do_mime, $do_dates,
469 $aliases
471 if (! empty($db_select)) {
472 $tmp_select = implode($db_select, '|');
473 $tmp_select = '|' . $tmp_select . '|';
475 // Walk over databases
476 foreach ($GLOBALS['pma']->databases as $current_db) {
477 if (isset($tmp_select)
478 && strpos(' ' . $tmp_select, '|' . $current_db . '|')
480 $tables = $GLOBALS['dbi']->getTables($current_db);
481 PMA_exportDatabase(
482 $current_db, $tables, $whatStrucOrData, $export_plugin, $crlf,
483 $err_url, $export_type, $do_relation, $do_comments, $do_mime,
484 $do_dates, $aliases
487 } // end foreach database
491 * Export at the database level
493 * @param string $db the database to export
494 * @param array $tables the tables to export
495 * @param string $whatStrucOrData structure or data or both
496 * @param object $export_plugin the selected export plugin
497 * @param string $crlf end of line character(s)
498 * @param string $err_url the URL in case of error
499 * @param string $export_type the export type
500 * @param bool $do_relation whether to export relation info
501 * @param bool $do_comments whether to add comments
502 * @param bool $do_mime whether to add MIME info
503 * @param bool $do_dates whether to add dates
504 * @param array $aliases Alias information for db/table/column
506 * @return void
508 function PMA_exportDatabase(
509 $db, $tables, $whatStrucOrData, $export_plugin, $crlf, $err_url,
510 $export_type, $do_relation, $do_comments, $do_mime, $do_dates,
511 $aliases
513 $db_alias = !empty($aliases[$db]['alias'])
514 ? $aliases[$db]['alias'] : '';
515 if (! $export_plugin->exportDBHeader($db, $db_alias)) {
516 return;
518 if (! $export_plugin->exportDBCreate($db, $db_alias)) {
519 return;
522 if (method_exists($export_plugin, 'exportRoutines')
523 && strpos($GLOBALS['sql_structure_or_data'], 'structure') !== false
524 && isset($GLOBALS['sql_procedure_function'])
526 $export_plugin->exportRoutines($db, $aliases);
529 $views = array();
531 foreach ($tables as $table) {
532 // if this is a view, collect it for later;
533 // views must be exported after the tables
534 $is_view = PMA_Table::isView($db, $table);
535 if ($is_view) {
536 $views[] = $table;
538 if ($whatStrucOrData == 'structure'
539 || $whatStrucOrData == 'structure_and_data'
541 // for a view, export a stand-in definition of the table
542 // to resolve view dependencies
544 if ($is_view) {
546 if (isset($GLOBALS['sql_create_view'])) {
547 if (! $export_plugin->exportStructure(
548 $db, $table, $crlf, $err_url, 'stand_in',
549 $export_type, $do_relation, $do_comments,
550 $do_mime, $do_dates, $aliases
551 )) {
552 break 1;
556 } else if (isset($GLOBALS['sql_create_table'])) {
558 $table_size = $GLOBALS['maxsize'];
559 // Checking if the maximum table size constrain has been set
560 // And if that constrain is a valid number or not
561 if ($table_size !== '' && is_numeric($table_size)) {
562 // This obtains the current table's size
563 $query = 'SELECT data_length + index_length
564 from information_schema.TABLES
565 WHERE table_schema = "' . $db . '"
566 AND table_name = "' . $table . '"';
568 $size = $GLOBALS['dbi']->fetchValue($query);
569 //Converting the size to MB
570 $size = ($size / 1024) / 1024;
571 if ($size > $table_size) {
572 continue;
576 if (! $export_plugin->exportStructure(
577 $db, $table, $crlf, $err_url, 'create_table',
578 $export_type, $do_relation, $do_comments,
579 $do_mime, $do_dates, $aliases
580 )) {
581 break 1;
587 // if this is a view or a merge table, don't export data
588 if (($whatStrucOrData == 'data'
589 || $whatStrucOrData == 'structure_and_data')
590 && ! ($is_view || PMA_Table::isMerge($db, $table))
592 $local_query = 'SELECT * FROM ' . PMA_Util::backquote($db)
593 . '.' . PMA_Util::backquote($table);
594 if (! $export_plugin->exportData(
595 $db, $table, $crlf, $err_url, $local_query, $aliases
596 )) {
597 break 1;
600 // now export the triggers (needs to be done after the data because
601 // triggers can modify already imported tables)
602 if (isset($GLOBALS['sql_create_trigger']) && ($whatStrucOrData == 'structure'
603 || $whatStrucOrData == 'structure_and_data')
605 if (! $export_plugin->exportStructure(
606 $db, $table, $crlf, $err_url, 'triggers',
607 $export_type, $do_relation, $do_comments,
608 $do_mime, $do_dates, $aliases
609 )) {
610 break 1;
615 if (isset($GLOBALS['sql_create_view'])) {
617 foreach ($views as $view) {
618 // no data export for a view
619 if ($whatStrucOrData == 'structure'
620 || $whatStrucOrData == 'structure_and_data'
622 if (! $export_plugin->exportStructure(
623 $db, $view, $crlf, $err_url, 'create_view',
624 $export_type, $do_relation, $do_comments,
625 $do_mime, $do_dates, $aliases
626 )) {
627 break 1;
634 if (! $export_plugin->exportDBFooter($db, $db_alias)) {
635 return;
640 * Export at the table level
642 * @param string $db the database to export
643 * @param string $table the table to export
644 * @param string $whatStrucOrData structure or data or both
645 * @param object $export_plugin the selected export plugin
646 * @param string $crlf end of line character(s)
647 * @param string $err_url the URL in case of error
648 * @param string $export_type the export type
649 * @param bool $do_relation whether to export relation info
650 * @param bool $do_comments whether to add comments
651 * @param bool $do_mime whether to add MIME info
652 * @param bool $do_dates whether to add dates
653 * @param string $allrows whether "dump all rows" was ticked
654 * @param string $limit_to upper limit
655 * @param string $limit_from starting limit
656 * @param string $sql_query query for which exporting is requested
657 * @param array $aliases Alias information for db/table/column
659 * @return void
661 function PMA_exportTable(
662 $db, $table, $whatStrucOrData, $export_plugin, $crlf, $err_url,
663 $export_type, $do_relation, $do_comments, $do_mime, $do_dates,
664 $allrows, $limit_to, $limit_from, $sql_query, $aliases
666 $db_alias = !empty($aliases[$db]['alias'])
667 ? $aliases[$db]['alias'] : '';
668 if (! $export_plugin->exportDBHeader($db, $db_alias)) {
669 return;
671 if (isset($allrows)
672 && $allrows == '0'
673 && $limit_to > 0
674 && $limit_from >= 0
676 $add_query = ' LIMIT '
677 . (($limit_from > 0) ? $limit_from . ', ' : '')
678 . $limit_to;
679 } else {
680 $add_query = '';
683 $is_view = PMA_Table::isView($db, $table);
684 if ($whatStrucOrData == 'structure'
685 || $whatStrucOrData == 'structure_and_data'
688 if ($is_view) {
690 if (isset($GLOBALS['sql_create_view'])) {
691 if (! $export_plugin->exportStructure(
692 $db, $table, $crlf, $err_url, 'create_view',
693 $export_type, $do_relation, $do_comments,
694 $do_mime, $do_dates, $aliases
695 )) {
696 return;
700 } else if (isset($GLOBALS['sql_create_table'])) {
702 if (! $export_plugin->exportStructure(
703 $db, $table, $crlf, $err_url, 'create_table',
704 $export_type, $do_relation, $do_comments,
705 $do_mime, $do_dates, $aliases
706 )) {
707 return;
713 // If this is an export of a single view, we have to export data;
714 // for example, a PDF report
715 // if it is a merge table, no data is exported
716 if (($whatStrucOrData == 'data'
717 || $whatStrucOrData == 'structure_and_data')
718 && ! PMA_Table::isMerge($db, $table)
720 if (! empty($sql_query)) {
721 // only preg_replace if needed
722 if (! empty($add_query)) {
723 // remove trailing semicolon before adding a LIMIT
724 $sql_query = preg_replace('%;\s*$%', '', $sql_query);
726 $local_query = $sql_query . $add_query;
727 $GLOBALS['dbi']->selectDb($db);
728 } else {
729 $local_query = 'SELECT * FROM ' . PMA_Util::backquote($db)
730 . '.' . PMA_Util::backquote($table) . $add_query;
732 if (! $export_plugin->exportData(
733 $db, $table, $crlf, $err_url, $local_query, $aliases
734 )) {
735 return;
738 // now export the triggers (needs to be done after the data because
739 // triggers can modify already imported tables)
740 if (isset($GLOBALS['sql_create_trigger']) && ($whatStrucOrData == 'structure'
741 || $whatStrucOrData == 'structure_and_data')
743 if (! $export_plugin->exportStructure(
744 $db, $table, $crlf, $err_url, 'triggers',
745 $export_type, $do_relation, $do_comments,
746 $do_mime, $do_dates, $aliases
747 )) {
748 return;
751 if (! $export_plugin->exportDBFooter($db, $db_alias)) {
752 return;
757 * Loads correct page after doing export
759 * @param string $db the database name
760 * @param string $table the table name
761 * @param string $export_type Export type
763 * @return void
765 function PMA_showExportPage($db, $table, $export_type)
767 global $cfg;
768 if ($export_type == 'server') {
769 $active_page = 'server_export.php';
770 include_once 'server_export.php';
771 } elseif ($export_type == 'database') {
772 $active_page = 'db_export.php';
773 include_once 'db_export.php';
774 } else {
775 $active_page = 'tbl_export.php';
776 include_once 'tbl_export.php';
778 exit();
782 * Merge two alias arrays, if array1 and array2 have
783 * conflicting alias then array2 value is used if it
784 * is non empty otherwise array1 value.
786 * @param array $aliases1 first array of aliases
787 * @param array $aliases2 second array of aliases
789 * @return array resultant merged aliases info
791 function PMA_mergeAliases($aliases1, $aliases2)
793 // First do a recursive array merge
794 // on aliases arrays.
795 $aliases = array_merge_recursive($aliases1, $aliases2);
796 // Now, resolve conflicts in aliases, if any
797 foreach ($aliases as $db_name => $db) {
798 // If alias key is an array then
799 // it is a merge conflict.
800 if (isset($db['alias']) && is_array($db['alias'])) {
801 $val1 = $db['alias'][0];
802 $val2 = $db['alias'][1];
803 // Use aliases2 alias if non empty
804 $aliases[$db_name]['alias']
805 = empty($val2) ? $val1 : $val2;
807 if (!isset($db['tables'])) {
808 continue;
810 foreach ($db['tables'] as $tbl_name => $tbl) {
811 if (isset($tbl['alias']) && is_array($tbl['alias'])) {
812 $val1 = $tbl['alias'][0];
813 $val2 = $tbl['alias'][1];
814 // Use aliases2 alias if non empty
815 $aliases[$db_name]['tables'][$tbl_name]['alias']
816 = empty($val2) ? $val1 : $val2;
818 if (!isset($tbl['columns'])) {
819 continue;
821 foreach ($tbl['columns'] as $col => $col_as) {
822 if (isset($col_as) && is_array($col_as)) {
823 $val1 = $col_as[0];
824 $val2 = $col_as[1];
825 // Use aliases2 alias if non empty
826 $aliases[$db_name]['tables'][$tbl_name]['columns'][$col]
827 = empty($val2) ? $val1 : $val2;
832 return $aliases;