Translated using Weblate (Slovenian)
[phpmyadmin.git] / import.php
blob72828e56fba805bc54bc4a34427a74107c4eae48
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 /**
4 * Core script for import, this is just the glue around all other stuff
6 * @package PhpMyAdmin
7 */
8 use PMA\libraries\plugins\ImportPlugin;
10 /* Enable LOAD DATA LOCAL INFILE for LDI plugin */
11 if (isset($_POST['format']) && $_POST['format'] == 'ldi') {
12 define('PMA_ENABLE_LDI', 1);
15 /**
16 * Get the variables sent or posted to this script and a core script
18 require_once 'libraries/common.inc.php';
19 require_once 'libraries/sql.lib.php';
20 require_once 'libraries/bookmark.lib.php';
21 //require_once 'libraries/display_import_functions.lib.php';
23 if (isset($_REQUEST['show_as_php'])) {
24 $GLOBALS['show_as_php'] = $_REQUEST['show_as_php'];
27 // Import functions.
28 require_once 'libraries/import.lib.php';
30 // If there is a request to 'Simulate DML'.
31 if (isset($_REQUEST['simulate_dml'])) {
32 PMA_handleSimulateDMLRequest();
33 exit;
36 // If it's a refresh console bookmarks request
37 if (isset($_REQUEST['console_bookmark_refresh'])) {
38 $response = PMA\libraries\Response::getInstance();
39 $response->addJSON(
40 'console_message_bookmark', PMA\libraries\Console::getBookmarkContent()
42 exit;
44 // If it's a console bookmark add request
45 if (isset($_REQUEST['console_bookmark_add'])) {
46 $response = PMA\libraries\Response::getInstance();
47 if (isset($_REQUEST['label']) && isset($_REQUEST['db'])
48 && isset($_REQUEST['bookmark_query']) && isset($_REQUEST['shared'])
49 ) {
50 $cfgBookmark = PMA_Bookmark_getParams();
51 $bookmarkFields = array(
52 'bkm_database' => $_REQUEST['db'],
53 'bkm_user' => $cfgBookmark['user'],
54 'bkm_sql_query' => $_REQUEST['bookmark_query'],
55 'bkm_label' => $_REQUEST['label']
57 $isShared = ($_REQUEST['shared'] == 'true' ? true : false);
58 if (PMA_Bookmark_save($bookmarkFields, $isShared)) {
59 $response->addJSON('message', __('Succeeded'));
60 $response->addJSON('data', $bookmarkFields);
61 $response->addJSON('isShared', $isShared);
62 } else {
63 $response->addJSON('message', __('Failed'));
65 die();
66 } else {
67 $response->addJSON('message', __('Incomplete params'));
68 die();
72 $format = '';
74 /**
75 * Sets globals from $_POST
77 $post_params = array(
78 'charset_of_file',
79 'format',
80 'import_type',
81 'is_js_confirmed',
82 'MAX_FILE_SIZE',
83 'message_to_show',
84 'noplugin',
85 'skip_queries',
86 'local_import_file'
89 // TODO: adapt full list of allowed parameters, as in export.php
90 foreach ($post_params as $one_post_param) {
91 if (isset($_POST[$one_post_param])) {
92 $GLOBALS[$one_post_param] = $_POST[$one_post_param];
96 // reset import messages for ajax request
97 $_SESSION['Import_message']['message'] = null;
98 $_SESSION['Import_message']['go_back_url'] = null;
99 // default values
100 $GLOBALS['reload'] = false;
102 // Use to identify current cycle is executing
103 // a multiquery statement or stored routine
104 if (!isset($_SESSION['is_multi_query'])) {
105 $_SESSION['is_multi_query'] = false;
108 $ajax_reload = array();
109 // Are we just executing plain query or sql file?
110 // (eg. non import, but query box/window run)
111 if (! empty($sql_query)) {
113 // apply values for parameters
114 if (! empty($_REQUEST['parameterized'])
115 && ! empty($_REQUEST['parameters'])
116 && is_array($_REQUEST['parameters'])) {
117 $parameters = $_REQUEST['parameters'];
118 foreach ($parameters as $parameter => $replacement) {
119 $quoted = preg_quote($parameter, '/');
120 // making sure that :param does not apply values to :param1
121 $sql_query = preg_replace(
122 '/' . $quoted . '([^a-zA-Z0-9_])/',
123 PMA\libraries\Util::sqlAddSlashes($replacement) . '${1}',
124 $sql_query
126 // for parameters the appear at the end of the string
127 $sql_query = preg_replace(
128 '/' . $quoted . '$/',
129 PMA\libraries\Util::sqlAddSlashes($replacement),
130 $sql_query
135 // run SQL query
136 $import_text = $sql_query;
137 $import_type = 'query';
138 $format = 'sql';
139 $_SESSION['sql_from_query_box'] = true;
141 // If there is a request to ROLLBACK when finished.
142 if (isset($_REQUEST['rollback_query'])) {
143 PMA_handleRollbackRequest($import_text);
146 // refresh navigation and main panels
147 if (preg_match('/^(DROP)\s+(VIEW|TABLE|DATABASE|SCHEMA)\s+/i', $sql_query)) {
148 $GLOBALS['reload'] = true;
149 $ajax_reload['reload'] = true;
152 // refresh navigation panel only
153 if (preg_match(
154 '/^(CREATE|ALTER)\s+(VIEW|TABLE|DATABASE|SCHEMA)\s+/i',
155 $sql_query
156 )) {
157 $ajax_reload['reload'] = true;
160 // do a dynamic reload if table is RENAMED
161 // (by sending the instruction to the AJAX response handler)
162 if (preg_match(
163 '/^RENAME\s+TABLE\s+(.*?)\s+TO\s+(.*?)($|;|\s)/i',
164 $sql_query,
165 $rename_table_names
166 )) {
167 $ajax_reload['reload'] = true;
168 $ajax_reload['table_name'] = PMA\libraries\Util::unQuote(
169 $rename_table_names[2]
173 $sql_query = '';
174 } elseif (! empty($sql_file)) {
175 // run uploaded SQL file
176 $import_file = $sql_file;
177 $import_type = 'queryfile';
178 $format = 'sql';
179 unset($sql_file);
180 } elseif (! empty($_REQUEST['id_bookmark'])) {
181 // run bookmark
182 $import_type = 'query';
183 $format = 'sql';
186 // If we didn't get any parameters, either user called this directly, or
187 // upload limit has been reached, let's assume the second possibility.
188 if ($_POST == array() && $_GET == array()) {
189 $message = PMA\libraries\Message::error(
191 'You probably tried to upload a file that is too large. Please refer ' .
192 'to %sdocumentation%s for a workaround for this limit.'
195 $message->addParam('[doc@faq1-16]');
196 $message->addParam('[/doc]');
198 // so we can obtain the message
199 $_SESSION['Import_message']['message'] = $message->getDisplay();
200 $_SESSION['Import_message']['go_back_url'] = $GLOBALS['goto'];
202 $message->display();
203 exit; // the footer is displayed automatically
206 // Add console message id to response output
207 if (isset($_POST['console_message_id'])) {
208 $response = PMA\libraries\Response::getInstance();
209 $response->addJSON('console_message_id', $_POST['console_message_id']);
213 * Sets globals from $_POST patterns, for import plugins
214 * We only need to load the selected plugin
217 if (! in_array(
218 $format,
219 array(
220 'csv',
221 'ldi',
222 'mediawiki',
223 'ods',
224 'shp',
225 'sql',
226 'xml'
230 // this should not happen for a normal user
231 // but only during an attack
232 PMA_fatalError('Incorrect format parameter');
235 $post_patterns = array(
236 '/^force_file_/',
237 '/^' . $format . '_/'
240 PMA_setPostAsGlobal($post_patterns);
242 // Check needed parameters
243 PMA\libraries\Util::checkParameters(array('import_type', 'format'));
245 // We don't want anything special in format
246 $format = PMA_securePath($format);
248 // Create error and goto url
249 if ($import_type == 'table') {
250 $err_url = 'tbl_import.php' . PMA_URL_getCommon(
251 array(
252 'db' => $db, 'table' => $table
255 $_SESSION['Import_message']['go_back_url'] = $err_url;
256 $goto = 'tbl_import.php';
257 } elseif ($import_type == 'database') {
258 $err_url = 'db_import.php' . PMA_URL_getCommon(array('db' => $db));
259 $_SESSION['Import_message']['go_back_url'] = $err_url;
260 $goto = 'db_import.php';
261 } elseif ($import_type == 'server') {
262 $err_url = 'server_import.php' . PMA_URL_getCommon();
263 $_SESSION['Import_message']['go_back_url'] = $err_url;
264 $goto = 'server_import.php';
265 } else {
266 if (empty($goto) || !preg_match('@^(server|db|tbl)(_[a-z]*)*\.php$@i', $goto)) {
267 if (mb_strlen($table) && mb_strlen($db)) {
268 $goto = 'tbl_structure.php';
269 } elseif (mb_strlen($db)) {
270 $goto = 'db_structure.php';
271 } else {
272 $goto = 'server_sql.php';
275 if (mb_strlen($table) && mb_strlen($db)) {
276 $common = PMA_URL_getCommon(array('db' => $db, 'table' => $table));
277 } elseif (mb_strlen($db)) {
278 $common = PMA_URL_getCommon(array('db' => $db));
279 } else {
280 $common = PMA_URL_getCommon();
282 $err_url = $goto . $common
283 . (preg_match('@^tbl_[a-z]*\.php$@', $goto)
284 ? '&amp;table=' . htmlspecialchars($table)
285 : '');
286 $_SESSION['Import_message']['go_back_url'] = $err_url;
288 // Avoid setting selflink to 'import.php'
289 // problem similar to bug 4276
290 if (basename($_SERVER['SCRIPT_NAME']) === 'import.php') {
291 $_SERVER['SCRIPT_NAME'] = $goto;
295 if (mb_strlen($db)) {
296 $GLOBALS['dbi']->selectDb($db);
299 @set_time_limit($cfg['ExecTimeLimit']);
300 if (! empty($cfg['MemoryLimit'])) {
301 @ini_set('memory_limit', $cfg['MemoryLimit']);
304 $timestamp = time();
305 if (isset($_REQUEST['allow_interrupt'])) {
306 $maximum_time = ini_get('max_execution_time');
307 } else {
308 $maximum_time = 0;
311 // set default values
312 $timeout_passed = false;
313 $error = false;
314 $read_multiply = 1;
315 $finished = false;
316 $offset = 0;
317 $max_sql_len = 0;
318 $file_to_unlink = '';
319 $sql_query = '';
320 $sql_query_disabled = false;
321 $go_sql = false;
322 $executed_queries = 0;
323 $run_query = true;
324 $charset_conversion = false;
325 $reset_charset = false;
326 $bookmark_created = false;
328 // Bookmark Support: get a query back from bookmark if required
329 if (! empty($_REQUEST['id_bookmark'])) {
330 $id_bookmark = (int)$_REQUEST['id_bookmark'];
331 include_once 'libraries/bookmark.lib.php';
332 switch ($_REQUEST['action_bookmark']) {
333 case 0: // bookmarked query that have to be run
334 $import_text = PMA_Bookmark_get(
335 $db,
336 $id_bookmark,
337 'id',
338 isset($_REQUEST['action_bookmark_all'])
340 if (! empty($_REQUEST['bookmark_variable'])) {
341 $import_text = PMA_Bookmark_applyVariables(
342 $import_text
346 // refresh navigation and main panels
347 if (preg_match(
348 '/^(DROP)\s+(VIEW|TABLE|DATABASE|SCHEMA)\s+/i',
349 $import_text
350 )) {
351 $GLOBALS['reload'] = true;
352 $ajax_reload['reload'] = true;
355 // refresh navigation panel only
356 if (preg_match(
357 '/^(CREATE|ALTER)\s+(VIEW|TABLE|DATABASE|SCHEMA)\s+/i',
358 $import_text
361 $ajax_reload['reload'] = true;
363 break;
364 case 1: // bookmarked query that have to be displayed
365 $import_text = PMA_Bookmark_get($db, $id_bookmark);
366 if ($GLOBALS['is_ajax_request'] == true) {
367 $message = PMA\libraries\Message::success(__('Showing bookmark'));
368 $response = PMA\libraries\Response::getInstance();
369 $response->setRequestStatus($message->isSuccess());
370 $response->addJSON('message', $message);
371 $response->addJSON('sql_query', $import_text);
372 $response->addJSON('action_bookmark', $_REQUEST['action_bookmark']);
373 exit;
374 } else {
375 $run_query = false;
377 break;
378 case 2: // bookmarked query that have to be deleted
379 $import_text = PMA_Bookmark_get($db, $id_bookmark);
380 PMA_Bookmark_delete($id_bookmark);
381 if ($GLOBALS['is_ajax_request'] == true) {
382 $message = PMA\libraries\Message::success(
383 __('The bookmark has been deleted.')
385 $response = PMA\libraries\Response::getInstance();
386 $response->setRequestStatus($message->isSuccess());
387 $response->addJSON('message', $message);
388 $response->addJSON('action_bookmark', $_REQUEST['action_bookmark']);
389 $response->addJSON('id_bookmark', $id_bookmark);
390 exit;
391 } else {
392 $run_query = false;
393 $error = true; // this is kind of hack to skip processing the query
395 break;
397 } // end bookmarks reading
399 // Do no run query if we show PHP code
400 if (isset($GLOBALS['show_as_php'])) {
401 $run_query = false;
402 $go_sql = true;
405 // We can not read all at once, otherwise we can run out of memory
406 $memory_limit = trim(@ini_get('memory_limit'));
407 // 2 MB as default
408 if (empty($memory_limit)) {
409 $memory_limit = 2 * 1024 * 1024;
411 // In case no memory limit we work on 10MB chunks
412 if ($memory_limit == -1) {
413 $memory_limit = 10 * 1024 * 1024;
416 // Calculate value of the limit
417 $memoryUnit = mb_strtolower(substr($memory_limit, -1));
418 if ('m' == $memoryUnit) {
419 $memory_limit = (int)substr($memory_limit, 0, -1) * 1024 * 1024;
420 } elseif ('k' == $memoryUnit) {
421 $memory_limit = (int)substr($memory_limit, 0, -1) * 1024;
422 } elseif ('g' == $memoryUnit) {
423 $memory_limit = (int)substr($memory_limit, 0, -1) * 1024 * 1024 * 1024;
424 } else {
425 $memory_limit = (int)$memory_limit;
428 // Just to be sure, there might be lot of memory needed for uncompression
429 $read_limit = $memory_limit / 8;
431 // handle filenames
432 if (isset($_FILES['import_file'])) {
433 $import_file = $_FILES['import_file']['tmp_name'];
435 if (! empty($local_import_file) && ! empty($cfg['UploadDir'])) {
437 // sanitize $local_import_file as it comes from a POST
438 $local_import_file = PMA_securePath($local_import_file);
440 $import_file = PMA\libraries\Util::userDir($cfg['UploadDir'])
441 . $local_import_file;
444 * Do not allow symlinks to avoid security issues
445 * (user can create symlink to file he can not access,
446 * but phpMyAdmin can).
448 if (@is_link($import_file)) {
449 $import_file = 'none';
452 } elseif (empty($import_file) || ! is_uploaded_file($import_file)) {
453 $import_file = 'none';
456 // Do we have file to import?
458 if ($import_file != 'none' && ! $error) {
459 // work around open_basedir and other limitations
460 $open_basedir = @ini_get('open_basedir');
462 // If we are on a server with open_basedir, we must move the file
463 // before opening it.
465 if (! empty($open_basedir)) {
466 $tmp_subdir = ini_get('upload_tmp_dir');
467 if (empty($tmp_subdir)) {
468 $tmp_subdir = sys_get_temp_dir();
470 $tmp_subdir = rtrim($tmp_subdir, DIRECTORY_SEPARATOR);
471 if (@is_writable($tmp_subdir)) {
472 $import_file_new = $tmp_subdir . DIRECTORY_SEPARATOR
473 . basename($import_file) . uniqid();
474 if (move_uploaded_file($import_file, $import_file_new)) {
475 $import_file = $import_file_new;
476 $file_to_unlink = $import_file_new;
479 $size = filesize($import_file);
480 } else {
482 // If the php.ini is misconfigured (eg. there is no /tmp access defined
483 // with open_basedir), $tmp_subdir won't be writable and the user gets
484 // a 'File could not be read!' error (at PMA_detectCompression), which
485 // is not too meaningful. Show a meaningful error message to the user
486 // instead.
488 $message = PMA\libraries\Message::error(
490 'Uploaded file cannot be moved, because the server has ' .
491 'open_basedir enabled without access to the %s directory ' .
492 '(for temporary files).'
495 $message->addParam($tmp_subdir);
496 PMA_stopImport($message);
501 * Handle file compression
502 * @todo duplicate code exists in File.php
504 $compression = PMA_detectCompression($import_file);
505 if ($compression === false) {
506 $message = PMA\libraries\Message::error(__('File could not be read!'));
507 PMA_stopImport($message); //Contains an 'exit'
510 switch ($compression) {
511 case 'application/bzip2':
512 if ($cfg['BZipDump'] && @function_exists('bzopen')) {
513 $import_handle = @bzopen($import_file, 'r');
514 } else {
515 $message = PMA\libraries\Message::error(
517 'You attempted to load file with unsupported compression ' .
518 '(%s). Either support for it is not implemented or disabled ' .
519 'by your configuration.'
522 $message->addParam($compression);
523 PMA_stopImport($message);
525 break;
526 case 'application/gzip':
527 if ($cfg['GZipDump'] && @function_exists('gzopen')) {
528 $import_handle = @gzopen($import_file, 'r');
529 } else {
530 $message = PMA\libraries\Message::error(
532 'You attempted to load file with unsupported compression ' .
533 '(%s). Either support for it is not implemented or disabled ' .
534 'by your configuration.'
537 $message->addParam($compression);
538 PMA_stopImport($message);
540 break;
541 case 'application/zip':
542 if ($cfg['ZipDump'] && @function_exists('zip_open')) {
544 * Load interface for zip extension.
546 include_once 'libraries/zip_extension.lib.php';
547 $zipResult = PMA_getZipContents($import_file);
548 if (! empty($zipResult['error'])) {
549 $message = PMA\libraries\Message::rawError($zipResult['error']);
550 PMA_stopImport($message);
551 } else {
552 $import_text = $zipResult['data'];
554 } else {
555 $message = PMA\libraries\Message::error(
557 'You attempted to load file with unsupported compression ' .
558 '(%s). Either support for it is not implemented or disabled ' .
559 'by your configuration.'
562 $message->addParam($compression);
563 PMA_stopImport($message);
565 break;
566 case 'none':
567 $import_handle = @fopen($import_file, 'r');
568 break;
569 default:
570 $message = PMA\libraries\Message::error(
572 'You attempted to load file with unsupported compression (%s). ' .
573 'Either support for it is not implemented or disabled by your ' .
574 'configuration.'
577 $message->addParam($compression);
578 PMA_stopImport($message);
579 // the previous function exits
581 // use isset() because zip compression type does not use a handle
582 if (! $error && isset($import_handle) && $import_handle === false) {
583 $message = PMA\libraries\Message::error(__('File could not be read!'));
584 PMA_stopImport($message);
586 } elseif (! $error) {
587 if (! isset($import_text) || empty($import_text)) {
588 $message = PMA\libraries\Message::error(
590 'No data was received to import. Either no file name was ' .
591 'submitted, or the file size exceeded the maximum size permitted ' .
592 'by your PHP configuration. See [doc@faq1-16]FAQ 1.16[/doc].'
595 PMA_stopImport($message);
599 // so we can obtain the message
600 //$_SESSION['Import_message'] = $message->getDisplay();
602 // Convert the file's charset if necessary
603 if ($GLOBALS['PMA_recoding_engine'] != PMA_CHARSET_NONE && isset($charset_of_file)) {
604 if ($charset_of_file != 'utf-8') {
605 $charset_conversion = true;
607 } elseif (isset($charset_of_file) && $charset_of_file != 'utf-8') {
608 $GLOBALS['dbi']->query('SET NAMES \'' . $charset_of_file . '\'');
609 // We can not show query in this case, it is in different charset
610 $sql_query_disabled = true;
611 $reset_charset = true;
614 // Something to skip? (because timeout has passed)
615 if (! $error && isset($_POST['skip'])) {
616 $original_skip = $skip = $_POST['skip'];
617 while ($skip > 0) {
618 PMA_importGetNextChunk($skip < $read_limit ? $skip : $read_limit);
619 // Disable read progressivity, otherwise we eat all memory!
620 $read_multiply = 1;
621 $skip -= $read_limit;
623 unset($skip);
626 // This array contain the data like numberof valid sql queries in the statement
627 // and complete valid sql statement (which affected for rows)
628 $sql_data = array('valid_sql' => array(), 'valid_queries' => 0);
630 if (! $error) {
631 // Check for file existence
632 include_once "libraries/plugin_interface.lib.php";
633 /* @var $import_plugin ImportPlugin */
634 $import_plugin = PMA_getPlugin(
635 "import",
636 $format,
637 'libraries/plugins/import/',
638 $import_type
640 if ($import_plugin == null) {
641 $message = PMA\libraries\Message::error(
642 __('Could not load import plugins, please check your installation!')
644 PMA_stopImport($message);
645 } else {
646 // Do the real import
647 try {
648 $default_fk_check = PMA\libraries\Util::handleDisableFKCheckInit();
649 $import_plugin->doImport($sql_data);
650 PMA\libraries\Util::handleDisableFKCheckCleanup($default_fk_check);
651 } catch (Exception $e) {
652 PMA\libraries\Util::handleDisableFKCheckCleanup($default_fk_check);
653 throw $e;
658 if (! empty($import_handle)) {
659 fclose($import_handle);
662 // Cleanup temporary file
663 if ($file_to_unlink != '') {
664 unlink($file_to_unlink);
667 // Reset charset back, if we did some changes
668 if ($reset_charset) {
669 $GLOBALS['dbi']->query('SET CHARACTER SET utf8');
670 $GLOBALS['dbi']->query(
671 'SET SESSION collation_connection =\'' . $collation_connection . '\''
675 // Show correct message
676 if (! empty($id_bookmark) && $_REQUEST['action_bookmark'] == 2) {
677 $message = PMA\libraries\Message::success(__('The bookmark has been deleted.'));
678 $display_query = $import_text;
679 $error = false; // unset error marker, it was used just to skip processing
680 } elseif (! empty($id_bookmark) && $_REQUEST['action_bookmark'] == 1) {
681 $message = PMA\libraries\Message::notice(__('Showing bookmark'));
682 } elseif ($bookmark_created) {
683 $special_message = '[br]' . sprintf(
684 __('Bookmark %s has been created.'),
685 htmlspecialchars($_POST['bkm_label'])
687 } elseif ($finished && ! $error) {
688 // Do not display the query with message, we do it separately
689 $display_query = ';';
690 if ($import_type != 'query') {
691 $message = PMA\libraries\Message::success(
692 '<em>'
693 . _ngettext(
694 'Import has been successfully finished, %d query executed.',
695 'Import has been successfully finished, %d queries executed.',
696 $executed_queries
698 . '</em>'
700 $message->addParam($executed_queries);
702 if ($import_notice) {
703 $message->addString($import_notice);
705 if (! empty($local_import_file)) {
706 $message->addString('(' . htmlspecialchars($local_import_file) . ')');
707 } else {
708 $message->addString(
709 '(' . htmlspecialchars($_FILES['import_file']['name']) . ')'
715 // Did we hit timeout? Tell it user.
716 if ($timeout_passed) {
717 $importUrl = $err_url .= '&timeout_passed=1&offset=' . urlencode(
718 $GLOBALS['offset']
720 if (isset($local_import_file)) {
721 $importUrl .= '&local_import_file=' . urlencode($local_import_file);
723 $message = PMA\libraries\Message::error(
725 'Script timeout passed, if you want to finish import,'
726 . ' please %sresubmit the same file%s and import will resume.'
729 $message->addParam('<a href="' . $importUrl . '">', false);
730 $message->addParam('</a>', false);
732 if ($offset == 0 || (isset($original_skip) && $original_skip == $offset)) {
733 $message->addString(
735 'However on last run no data has been parsed,'
736 . ' this usually means phpMyAdmin won\'t be able to'
737 . ' finish this import unless you increase php time limits.'
743 // if there is any message, copy it into $_SESSION as well,
744 // so we can obtain it by AJAX call
745 if (isset($message)) {
746 $_SESSION['Import_message']['message'] = $message->getDisplay();
748 // Parse and analyze the query, for correct db and table name
749 // in case of a query typed in the query window
750 // (but if the query is too large, in case of an imported file, the parser
751 // can choke on it so avoid parsing)
752 $sqlLength = mb_strlen($sql_query);
753 if ($sqlLength <= $GLOBALS['cfg']['MaxCharactersInDisplayedSQL']) {
754 include_once 'libraries/parse_analyze.lib.php';
756 list(
757 $analyzed_sql_results,
758 $db,
759 $table_from_sql
760 ) = PMA_parseAnalyze($sql_query, $db);
761 // @todo: possibly refactor
762 extract($analyzed_sql_results);
764 if ($table != $table_from_sql && !empty($table_from_sql)) {
765 $table = $table_from_sql;
769 // There was an error?
770 if (isset($my_die)) {
771 foreach ($my_die as $key => $die) {
772 PMA\libraries\Util::mysqlDie(
773 $die['error'], $die['sql'], false, $err_url, $error
778 if ($go_sql) {
780 if (! empty($sql_data) && ($sql_data['valid_queries'] > 1)) {
781 $_SESSION['is_multi_query'] = true;
782 $sql_queries = $sql_data['valid_sql'];
783 } else {
784 $sql_queries = array($sql_query);
787 $html_output = '';
788 foreach ($sql_queries as $sql_query) {
790 // parse sql query
791 include_once 'libraries/parse_analyze.lib.php';
792 list(
793 $analyzed_sql_results,
794 $db,
795 $table_from_sql
796 ) = PMA_parseAnalyze($sql_query, $db);
797 // @todo: possibly refactor
798 extract($analyzed_sql_results);
800 // Check if User is allowed to issue a 'DROP DATABASE' Statement
801 if (PMA_hasNoRightsToDropDatabase(
802 $analyzed_sql_results, $cfg['AllowUserDropDatabase'], $GLOBALS['is_superuser']
803 )) {
804 PMA\libraries\Util::mysqlDie(
805 __('"DROP DATABASE" statements are disabled.'),
807 false,
808 $_SESSION['Import_message']['go_back_url']
810 return;
811 } // end if
813 if ($table != $table_from_sql && !empty($table_from_sql)) {
814 $table = $table_from_sql;
817 $html_output .= PMA_executeQueryAndGetQueryResponse(
818 $analyzed_sql_results, // analyzed_sql_results
819 false, // is_gotofile
820 $db, // db
821 $table, // table
822 null, // find_real_end
823 $_REQUEST['sql_query'], // sql_query_for_bookmark
824 null, // extra_data
825 null, // message_to_show
826 null, // message
827 null, // sql_data
828 $goto, // goto
829 $pmaThemeImage, // pmaThemeImage
830 null, // disp_query
831 null, // disp_message
832 null, // query_type
833 $sql_query, // sql_query
834 null, // selectedTables
835 null // complete_query
839 $response = PMA\libraries\Response::getInstance();
840 $response->addJSON('ajax_reload', $ajax_reload);
841 $response->addHTML($html_output);
842 exit();
844 } else if ($result) {
845 // Save a Bookmark with more than one queries (if Bookmark label given).
846 if (! empty($_POST['bkm_label']) && ! empty($import_text)) {
847 $cfgBookmark = PMA_Bookmark_getParams();
848 PMA_storeTheQueryAsBookmark(
849 $db, $cfgBookmark['user'],
850 $_REQUEST['sql_query'], $_POST['bkm_label'],
851 isset($_POST['bkm_replace']) ? $_POST['bkm_replace'] : null
855 $response = PMA\libraries\Response::getInstance();
856 $response->setRequestStatus(true);
857 $response->addJSON('message', PMA\libraries\Message::success($msg));
858 $response->addJSON(
859 'sql_query',
860 PMA\libraries\Util::getMessage($msg, $sql_query, 'success')
862 } else if ($result == false) {
863 $response = PMA\libraries\Response::getInstance();
864 $response->setRequestStatus(false);
865 $response->addJSON('message', PMA\libraries\Message::error($msg));
866 } else {
867 $active_page = $goto;
868 include '' . $goto;
871 // If there is request for ROLLBACK in the end.
872 if (isset($_REQUEST['rollback_query'])) {
873 $GLOBALS['dbi']->query('ROLLBACK');