Translated using Weblate (Tatar)
[phpmyadmin.git] / import.php
blobd2ec298edb3e9880c9182603e01fd11683207e3f
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;
9 use PMA\libraries\PMA_String;
11 /**
12 * Get the variables sent or posted to this script and a core script
14 require_once 'libraries/common.inc.php';
15 require_once 'libraries/sql.lib.php';
16 require_once 'libraries/bookmark.lib.php';
17 //require_once 'libraries/display_import_functions.lib.php';
19 if (isset($_REQUEST['show_as_php'])) {
20 $GLOBALS['show_as_php'] = $_REQUEST['show_as_php'];
23 // Import functions.
24 require_once 'libraries/import.lib.php';
26 // If there is a request to 'Simulate DML'.
27 if (isset($_REQUEST['simulate_dml'])) {
28 PMA_handleSimulateDMLRequest();
29 exit;
32 // If it's a refresh console bookmarks request
33 if (isset($_REQUEST['console_bookmark_refresh'])) {
34 $response = PMA\libraries\Response::getInstance();
35 $response->addJSON(
36 'console_message_bookmark', PMA\libraries\Console::getBookmarkContent()
38 exit;
40 // If it's a console bookmark add request
41 if (isset($_REQUEST['console_bookmark_add'])) {
42 $response = PMA\libraries\Response::getInstance();
43 if (isset($_REQUEST['label']) && isset($_REQUEST['db'])
44 && isset($_REQUEST['bookmark_query']) && isset($_REQUEST['shared'])
45 ) {
46 $cfgBookmark = PMA_Bookmark_getParams();
47 $bookmarkFields = array(
48 'bkm_database' => $_REQUEST['db'],
49 'bkm_user' => $cfgBookmark['user'],
50 'bkm_sql_query' => urlencode($_REQUEST['bookmark_query']),
51 'bkm_label' => $_REQUEST['label']
53 $isShared = ($_REQUEST['shared'] == 'true' ? true : false);
54 if (PMA_Bookmark_save($bookmarkFields, $isShared)) {
55 $response->addJSON('message', __('Succeeded'));
56 $response->addJSON('data', $bookmarkFields);
57 $response->addJSON('isShared', $isShared);
58 } else {
59 $response->addJSON('message', __('Failed'));
61 die();
62 } else {
63 $response->addJSON('message', __('Incomplete params'));
64 die();
68 /**
69 * Sets globals from $_POST
71 $post_params = array(
72 'charset_of_file',
73 'format',
74 'import_type',
75 'is_js_confirmed',
76 'MAX_FILE_SIZE',
77 'message_to_show',
78 'noplugin',
79 'skip_queries',
80 'local_import_file'
83 // TODO: adapt full list of allowed parameters, as in export.php
84 foreach ($post_params as $one_post_param) {
85 if (isset($_POST[$one_post_param])) {
86 $GLOBALS[$one_post_param] = $_POST[$one_post_param];
90 // reset import messages for ajax request
91 $_SESSION['Import_message']['message'] = null;
92 $_SESSION['Import_message']['go_back_url'] = null;
93 // default values
94 $GLOBALS['reload'] = false;
96 // Use to identify current cycle is executing
97 // a multiquery statement or stored routine
98 if (!isset($_SESSION['is_multi_query'])) {
99 $_SESSION['is_multi_query'] = false;
102 $ajax_reload = array();
103 // Are we just executing plain query or sql file?
104 // (eg. non import, but query box/window run)
105 if (! empty($sql_query)) {
107 // apply values for parameters
108 if (! empty($_REQUEST['parameterized'])) {
109 $parameters = $_REQUEST['parameters'];
110 foreach ($parameters as $parameter => $replacement) {
111 $quoted = preg_quote($parameter);
112 // making sure that :param does not apply values to :param1
113 $sql_query = preg_replace(
114 '/' . $quoted . '([^a-zA-Z0-9_])/',
115 PMA\libraries\Util::sqlAddSlashes($replacement) . '${1}',
116 $sql_query
118 // for parameters the appear at the end of the string
119 $sql_query = preg_replace(
120 '/' . $quoted . '$/',
121 PMA\libraries\Util::sqlAddSlashes($replacement),
122 $sql_query
127 // run SQL query
128 $import_text = $sql_query;
129 $import_type = 'query';
130 $format = 'sql';
131 $_SESSION['sql_from_query_box'] = true;
133 // If there is a request to ROLLBACK when finished.
134 if (isset($_REQUEST['rollback_query'])) {
135 PMA_handleRollbackRequest($import_text);
138 // refresh navigation and main panels
139 if (preg_match('/^(DROP)\s+(VIEW|TABLE|DATABASE|SCHEMA)\s+/i', $sql_query)) {
140 $GLOBALS['reload'] = true;
141 $ajax_reload['reload'] = true;
144 // refresh navigation panel only
145 if (preg_match(
146 '/^(CREATE|ALTER)\s+(VIEW|TABLE|DATABASE|SCHEMA)\s+/i',
147 $sql_query
148 )) {
149 $ajax_reload['reload'] = true;
152 // do a dynamic reload if table is RENAMED
153 // (by sending the instruction to the AJAX response handler)
154 if (preg_match(
155 '/^RENAME\s+TABLE\s+(.*?)\s+TO\s+(.*?)($|;|\s)/i',
156 $sql_query,
157 $rename_table_names
158 )) {
159 $ajax_reload['reload'] = true;
160 $ajax_reload['table_name'] = PMA\libraries\Util::unQuote($rename_table_names[2]);
163 $sql_query = '';
164 } elseif (! empty($sql_file)) {
165 // run uploaded SQL file
166 $import_file = $sql_file;
167 $import_type = 'queryfile';
168 $format = 'sql';
169 unset($sql_file);
170 } elseif (! empty($_REQUEST['id_bookmark'])) {
171 // run bookmark
172 $import_type = 'query';
173 $format = 'sql';
176 // If we didn't get any parameters, either user called this directly, or
177 // upload limit has been reached, let's assume the second possibility.
178 if ($_POST == array() && $_GET == array()) {
179 $message = PMA\libraries\Message::error(
181 'You probably tried to upload a file that is too large. Please refer ' .
182 'to %sdocumentation%s for a workaround for this limit.'
185 $message->addParam('[doc@faq1-16]');
186 $message->addParam('[/doc]');
188 // so we can obtain the message
189 $_SESSION['Import_message']['message'] = $message->getDisplay();
190 $_SESSION['Import_message']['go_back_url'] = $GLOBALS['goto'];
192 $message->display();
193 exit; // the footer is displayed automatically
196 // Add console message id to response output
197 if (isset($_POST['console_message_id'])) {
198 $response = PMA\libraries\Response::getInstance();
199 $response->addJSON('console_message_id', $_POST['console_message_id']);
203 * Sets globals from $_POST patterns, for import plugins
204 * We only need to load the selected plugin
207 if (! in_array(
208 $format,
209 array(
210 'csv',
211 'ldi',
212 'mediawiki',
213 'ods',
214 'shp',
215 'sql',
216 'xml'
220 // this should not happen for a normal user
221 // but only during an attack
222 PMA_fatalError('Incorrect format parameter');
225 $post_patterns = array(
226 '/^force_file_/',
227 '/^' . $format . '_/'
230 PMA_setPostAsGlobal($post_patterns);
232 // Check needed parameters
233 PMA\libraries\Util::checkParameters(array('import_type', 'format'));
235 // We don't want anything special in format
236 $format = PMA_securePath($format);
237 /** @var String $pmaString */
238 $pmaString = $GLOBALS['PMA_String'];
240 // Create error and goto url
241 if ($import_type == 'table') {
242 $err_url = 'tbl_import.php' . PMA_URL_getCommon(
243 array(
244 'db' => $db, 'table' => $table
247 $_SESSION['Import_message']['go_back_url'] = $err_url;
248 $goto = 'tbl_import.php';
249 } elseif ($import_type == 'database') {
250 $err_url = 'db_import.php' . PMA_URL_getCommon(array('db' => $db));
251 $_SESSION['Import_message']['go_back_url'] = $err_url;
252 $goto = 'db_import.php';
253 } elseif ($import_type == 'server') {
254 $err_url = 'server_import.php' . PMA_URL_getCommon();
255 $_SESSION['Import_message']['go_back_url'] = $err_url;
256 $goto = 'server_import.php';
257 } else {
258 if (empty($goto) || !preg_match('@^(server|db|tbl)(_[a-z]*)*\.php$@i', $goto)) {
259 if (/*overload*/mb_strlen($table) && /*overload*/mb_strlen($db)) {
260 $goto = 'tbl_structure.php';
261 } elseif (/*overload*/mb_strlen($db)) {
262 $goto = 'db_structure.php';
263 } else {
264 $goto = 'server_sql.php';
267 if (/*overload*/mb_strlen($table) && /*overload*/mb_strlen($db)) {
268 $common = PMA_URL_getCommon(array('db' => $db, 'table' => $table));
269 } elseif (/*overload*/mb_strlen($db)) {
270 $common = PMA_URL_getCommon(array('db' => $db));
271 } else {
272 $common = PMA_URL_getCommon();
274 $err_url = $goto . $common
275 . (preg_match('@^tbl_[a-z]*\.php$@', $goto)
276 ? '&amp;table=' . htmlspecialchars($table)
277 : '');
278 $_SESSION['Import_message']['go_back_url'] = $err_url;
280 // Avoid setting selflink to 'import.php'
281 // problem similar to bug 4276
282 if (basename($_SERVER['SCRIPT_NAME']) === 'import.php') {
283 $_SERVER['SCRIPT_NAME'] = $goto;
287 if (/*overload*/mb_strlen($db)) {
288 $GLOBALS['dbi']->selectDb($db);
291 @set_time_limit($cfg['ExecTimeLimit']);
292 if (! empty($cfg['MemoryLimit'])) {
293 @ini_set('memory_limit', $cfg['MemoryLimit']);
296 $timestamp = time();
297 if (isset($_REQUEST['allow_interrupt'])) {
298 $maximum_time = ini_get('max_execution_time');
299 } else {
300 $maximum_time = 0;
303 // set default values
304 $timeout_passed = false;
305 $error = false;
306 $read_multiply = 1;
307 $finished = false;
308 $offset = 0;
309 $max_sql_len = 0;
310 $file_to_unlink = '';
311 $sql_query = '';
312 $sql_query_disabled = false;
313 $go_sql = false;
314 $executed_queries = 0;
315 $run_query = true;
316 $charset_conversion = false;
317 $reset_charset = false;
318 $bookmark_created = false;
320 // Bookmark Support: get a query back from bookmark if required
321 if (! empty($_REQUEST['id_bookmark'])) {
322 $id_bookmark = (int)$_REQUEST['id_bookmark'];
323 include_once 'libraries/bookmark.lib.php';
324 switch ($_REQUEST['action_bookmark']) {
325 case 0: // bookmarked query that have to be run
326 $import_text = PMA_Bookmark_get(
327 $db,
328 $id_bookmark,
329 'id',
330 isset($_REQUEST['action_bookmark_all'])
332 if (! empty($_REQUEST['bookmark_variable'])) {
333 $import_text = PMA_Bookmark_applyVariables(
334 $import_text
338 // refresh navigation and main panels
339 if (preg_match(
340 '/^(DROP)\s+(VIEW|TABLE|DATABASE|SCHEMA)\s+/i',
341 $import_text
342 )) {
343 $GLOBALS['reload'] = true;
344 $ajax_reload['reload'] = true;
347 // refresh navigation panel only
348 if (preg_match(
349 '/^(CREATE|ALTER)\s+(VIEW|TABLE|DATABASE|SCHEMA)\s+/i',
350 $import_text
353 $ajax_reload['reload'] = true;
355 break;
356 case 1: // bookmarked query that have to be displayed
357 $import_text = PMA_Bookmark_get($db, $id_bookmark);
358 if ($GLOBALS['is_ajax_request'] == true) {
359 $message = PMA\libraries\Message::success(__('Showing bookmark'));
360 $response = PMA\libraries\Response::getInstance();
361 $response->setRequestStatus($message->isSuccess());
362 $response->addJSON('message', $message);
363 $response->addJSON('sql_query', $import_text);
364 $response->addJSON('action_bookmark', $_REQUEST['action_bookmark']);
365 exit;
366 } else {
367 $run_query = false;
369 break;
370 case 2: // bookmarked query that have to be deleted
371 $import_text = PMA_Bookmark_get($db, $id_bookmark);
372 PMA_Bookmark_delete($id_bookmark);
373 if ($GLOBALS['is_ajax_request'] == true) {
374 $message = PMA\libraries\Message::success(__('The bookmark has been deleted.'));
375 $response = PMA\libraries\Response::getInstance();
376 $response->setRequestStatus($message->isSuccess());
377 $response->addJSON('message', $message);
378 $response->addJSON('action_bookmark', $_REQUEST['action_bookmark']);
379 $response->addJSON('id_bookmark', $id_bookmark);
380 exit;
381 } else {
382 $run_query = false;
383 $error = true; // this is kind of hack to skip processing the query
385 break;
387 } // end bookmarks reading
389 // Do no run query if we show PHP code
390 if (isset($GLOBALS['show_as_php'])) {
391 $run_query = false;
392 $go_sql = true;
395 // We can not read all at once, otherwise we can run out of memory
396 $memory_limit = trim(@ini_get('memory_limit'));
397 // 2 MB as default
398 if (empty($memory_limit)) {
399 $memory_limit = 2 * 1024 * 1024;
401 // In case no memory limit we work on 10MB chunks
402 if ($memory_limit == -1) {
403 $memory_limit = 10 * 1024 * 1024;
406 // Calculate value of the limit
407 $memoryUnit = /*overload*/mb_strtolower(substr($memory_limit, -1));
408 if ('m' == $memoryUnit) {
409 $memory_limit = (int)substr($memory_limit, 0, -1) * 1024 * 1024;
410 } elseif ('k' == $memoryUnit) {
411 $memory_limit = (int)substr($memory_limit, 0, -1) * 1024;
412 } elseif ('g' == $memoryUnit) {
413 $memory_limit = (int)substr($memory_limit, 0, -1) * 1024 * 1024 * 1024;
414 } else {
415 $memory_limit = (int)$memory_limit;
418 // Just to be sure, there might be lot of memory needed for uncompression
419 $read_limit = $memory_limit / 8;
421 // handle filenames
422 if (isset($_FILES['import_file'])) {
423 $import_file = $_FILES['import_file']['tmp_name'];
425 if (! empty($local_import_file) && ! empty($cfg['UploadDir'])) {
427 // sanitize $local_import_file as it comes from a POST
428 $local_import_file = PMA_securePath($local_import_file);
430 $import_file = PMA\libraries\Util::userDir($cfg['UploadDir'])
431 . $local_import_file;
433 } elseif (empty($import_file) || ! is_uploaded_file($import_file)) {
434 $import_file = 'none';
437 // Do we have file to import?
439 if ($import_file != 'none' && ! $error) {
440 // work around open_basedir and other limitations
441 $open_basedir = @ini_get('open_basedir');
443 // If we are on a server with open_basedir, we must move the file
444 // before opening it.
446 if (! empty($open_basedir)) {
447 $tmp_subdir = ini_get('upload_tmp_dir');
448 if (empty($tmp_subdir)) {
449 $tmp_subdir = sys_get_temp_dir();
451 $tmp_subdir = rtrim($tmp_subdir, DIRECTORY_SEPARATOR);
452 if (is_writable($tmp_subdir)) {
453 $import_file_new = $tmp_subdir . DIRECTORY_SEPARATOR
454 . basename($import_file) . uniqid();
455 if (move_uploaded_file($import_file, $import_file_new)) {
456 $import_file = $import_file_new;
457 $file_to_unlink = $import_file_new;
460 $size = filesize($import_file);
461 } else {
463 // If the php.ini is misconfigured (eg. there is no /tmp access defined
464 // with open_basedir), $tmp_subdir won't be writable and the user gets
465 // a 'File could not be read!' error (at PMA_detectCompression), which
466 // is not too meaningful. Show a meaningful error message to the user
467 // instead.
469 $message = PMA\libraries\Message::error(
471 'Uploaded file cannot be moved, because the server has ' .
472 'open_basedir enabled without access to the %s directory ' .
473 '(for temporary files).'
476 $message->addParam($tmp_subdir);
477 PMA_stopImport($message);
482 * Handle file compression
483 * @todo duplicate code exists in File.php
485 $compression = PMA_detectCompression($import_file);
486 if ($compression === false) {
487 $message = PMA\libraries\Message::error(__('File could not be read!'));
488 PMA_stopImport($message); //Contains an 'exit'
491 switch ($compression) {
492 case 'application/bzip2':
493 if ($cfg['BZipDump'] && @function_exists('bzopen')) {
494 $import_handle = @bzopen($import_file, 'r');
495 } else {
496 $message = PMA\libraries\Message::error(
498 'You attempted to load file with unsupported compression ' .
499 '(%s). Either support for it is not implemented or disabled ' .
500 'by your configuration.'
503 $message->addParam($compression);
504 PMA_stopImport($message);
506 break;
507 case 'application/gzip':
508 if ($cfg['GZipDump'] && @function_exists('gzopen')) {
509 $import_handle = @gzopen($import_file, 'r');
510 } else {
511 $message = PMA\libraries\Message::error(
513 'You attempted to load file with unsupported compression ' .
514 '(%s). Either support for it is not implemented or disabled ' .
515 'by your configuration.'
518 $message->addParam($compression);
519 PMA_stopImport($message);
521 break;
522 case 'application/zip':
523 if ($cfg['ZipDump'] && @function_exists('zip_open')) {
525 * Load interface for zip extension.
527 include_once 'libraries/zip_extension.lib.php';
528 $zipResult = PMA_getZipContents($import_file);
529 if (! empty($zipResult['error'])) {
530 $message = PMA\libraries\Message::rawError($zipResult['error']);
531 PMA_stopImport($message);
532 } else {
533 $import_text = $zipResult['data'];
535 } else {
536 $message = PMA\libraries\Message::error(
538 'You attempted to load file with unsupported compression ' .
539 '(%s). Either support for it is not implemented or disabled ' .
540 'by your configuration.'
543 $message->addParam($compression);
544 PMA_stopImport($message);
546 break;
547 case 'none':
548 $import_handle = @fopen($import_file, 'r');
549 break;
550 default:
551 $message = PMA\libraries\Message::error(
553 'You attempted to load file with unsupported compression (%s). ' .
554 'Either support for it is not implemented or disabled by your ' .
555 'configuration.'
558 $message->addParam($compression);
559 PMA_stopImport($message);
560 break;
562 // use isset() because zip compression type does not use a handle
563 if (! $error && isset($import_handle) && $import_handle === false) {
564 $message = PMA\libraries\Message::error(__('File could not be read!'));
565 PMA_stopImport($message);
567 } elseif (! $error) {
568 if (! isset($import_text) || empty($import_text)) {
569 $message = PMA\libraries\Message::error(
571 'No data was received to import. Either no file name was ' .
572 'submitted, or the file size exceeded the maximum size permitted ' .
573 'by your PHP configuration. See [doc@faq1-16]FAQ 1.16[/doc].'
576 PMA_stopImport($message);
580 // so we can obtain the message
581 //$_SESSION['Import_message'] = $message->getDisplay();
583 // Convert the file's charset if necessary
584 if ($GLOBALS['PMA_recoding_engine'] != PMA_CHARSET_NONE && isset($charset_of_file)) {
585 if ($charset_of_file != 'utf-8') {
586 $charset_conversion = true;
588 } elseif (isset($charset_of_file) && $charset_of_file != 'utf-8') {
589 $GLOBALS['dbi']->query('SET NAMES \'' . $charset_of_file . '\'');
590 // We can not show query in this case, it is in different charset
591 $sql_query_disabled = true;
592 $reset_charset = true;
595 // Something to skip? (because timeout has passed)
596 if (! $error && isset($_POST['skip'])) {
597 $original_skip = $skip = $_POST['skip'];
598 while ($skip > 0) {
599 PMA_importGetNextChunk($skip < $read_limit ? $skip : $read_limit);
600 // Disable read progressivity, otherwise we eat all memory!
601 $read_multiply = 1;
602 $skip -= $read_limit;
604 unset($skip);
607 // This array contain the data like numberof valid sql queries in the statement
608 // and complete valid sql statement (which affected for rows)
609 $sql_data = array('valid_sql' => array(), 'valid_queries' => 0);
611 if (! $error) {
612 // Check for file existence
613 include_once "libraries/plugin_interface.lib.php";
614 /* @var $import_plugin ImportPlugin */
615 $import_plugin = PMA_getPlugin(
616 "import",
617 $format,
618 'libraries/plugins/import/',
619 $import_type
621 if ($import_plugin == null) {
622 $message = PMA\libraries\Message::error(
623 __('Could not load import plugins, please check your installation!')
625 PMA_stopImport($message);
626 } else {
627 // Do the real import
628 try {
629 $default_fk_check = PMA\libraries\Util::handleDisableFKCheckInit();
630 $import_plugin->doImport($sql_data);
631 PMA\libraries\Util::handleDisableFKCheckCleanup($default_fk_check);
632 } catch (Exception $e) {
633 PMA\libraries\Util::handleDisableFKCheckCleanup($default_fk_check);
634 throw $e;
639 if (! empty($import_handle)) {
640 fclose($import_handle);
643 // Cleanup temporary file
644 if ($file_to_unlink != '') {
645 unlink($file_to_unlink);
648 // Reset charset back, if we did some changes
649 if ($reset_charset) {
650 $GLOBALS['dbi']->query('SET CHARACTER SET utf8');
651 $GLOBALS['dbi']->query(
652 'SET SESSION collation_connection =\'' . $collation_connection . '\''
656 // Show correct message
657 if (! empty($id_bookmark) && $_REQUEST['action_bookmark'] == 2) {
658 $message = PMA\libraries\Message::success(__('The bookmark has been deleted.'));
659 $display_query = $import_text;
660 $error = false; // unset error marker, it was used just to skip processing
661 } elseif (! empty($id_bookmark) && $_REQUEST['action_bookmark'] == 1) {
662 $message = PMA\libraries\Message::notice(__('Showing bookmark'));
663 } elseif ($bookmark_created) {
664 $special_message = '[br]' . sprintf(
665 __('Bookmark %s has been created.'),
666 htmlspecialchars($_POST['bkm_label'])
668 } elseif ($finished && ! $error) {
669 if ($import_type == 'query') {
670 $message = PMA\libraries\Message::success();
671 } else {
672 $message = PMA\libraries\Message::success(
673 '<em>'
674 . __('Import has been successfully finished, %d queries executed.')
675 . '</em>'
677 $message->addParam($executed_queries);
679 if ($import_notice) {
680 $message->addString($import_notice);
682 if (! empty($local_import_file)) {
683 $message->addString('(' . htmlspecialchars($local_import_file) . ')');
684 } else {
685 $message->addString(
686 '(' . htmlspecialchars($_FILES['import_file']['name']) . ')'
692 // Did we hit timeout? Tell it user.
693 if ($timeout_passed) {
694 $importUrl = $err_url .= '&timeout_passed=1&offset=' . urlencode(
695 $GLOBALS['offset']
697 if (isset($local_import_file)) {
698 $importUrl .= '&local_import_file=' . urlencode($local_import_file);
700 $message = PMA\libraries\Message::error(
702 'Script timeout passed, if you want to finish import,'
703 . ' please %sresubmit the same file%s and import will resume.'
706 $message->addParam('<a href="' . $importUrl . '">', false);
707 $message->addParam('</a>', false);
709 if ($offset == 0 || (isset($original_skip) && $original_skip == $offset)) {
710 $message->addString(
712 'However on last run no data has been parsed,'
713 . ' this usually means phpMyAdmin won\'t be able to'
714 . ' finish this import unless you increase php time limits.'
720 // if there is any message, copy it into $_SESSION as well,
721 // so we can obtain it by AJAX call
722 if (isset($message)) {
723 $_SESSION['Import_message']['message'] = $message->getDisplay();
725 // Parse and analyze the query, for correct db and table name
726 // in case of a query typed in the query window
727 // (but if the query is too large, in case of an imported file, the parser
728 // can choke on it so avoid parsing)
729 $sqlLength = /*overload*/mb_strlen($sql_query);
730 if ($sqlLength <= $GLOBALS['cfg']['MaxCharactersInDisplayedSQL']) {
731 include_once 'libraries/parse_analyze.inc.php';
734 // There was an error?
735 if (isset($my_die)) {
736 foreach ($my_die as $key => $die) {
737 PMA\libraries\Util::mysqlDie(
738 $die['error'], $die['sql'], false, $err_url, $error
743 if ($go_sql) {
745 if (! empty($sql_data) && ($sql_data['valid_queries'] > 1)) {
746 $_SESSION['is_multi_query'] = true;
747 $sql_queries = $sql_data['valid_sql'];
748 } else {
749 $sql_queries = array($sql_query);
752 $html_output = '';
753 foreach ($sql_queries as $sql_query) {
754 // parse sql query
755 include 'libraries/parse_analyze.inc.php';
757 $html_output .= PMA_executeQueryAndGetQueryResponse(
758 $analyzed_sql_results, // analyzed_sql_results
759 false, // is_gotofile
760 $db, // db
761 $table, // table
762 null, // find_real_end
763 $sql_query, // sql_query_for_bookmark
764 null, // extra_data
765 null, // message_to_show
766 null, // message
767 null, // sql_data
768 $goto, // goto
769 $pmaThemeImage, // pmaThemeImage
770 null, // disp_query
771 null, // disp_message
772 null, // query_type
773 $sql_query, // sql_query
774 null, // selectedTables
775 null // complete_query
779 $response = PMA\libraries\Response::getInstance();
780 $response->addJSON('ajax_reload', $ajax_reload);
781 $response->addHTML($html_output);
782 exit();
784 } else if ($result) {
785 // Save a Bookmark with more than one queries (if Bookmark label given).
786 if (! empty($_POST['bkm_label']) && ! empty($import_text)) {
787 $cfgBookmark = PMA_Bookmark_getParams();
788 PMA_storeTheQueryAsBookmark(
789 $db, $cfgBookmark['user'],
790 $_REQUEST['sql_query'], $_POST['bkm_label'],
791 isset($_POST['bkm_replace']) ? $_POST['bkm_replace'] : null
795 $response = PMA\libraries\Response::getInstance();
796 $response->setRequestStatus(true);
797 $response->addJSON('message', PMA\libraries\Message::success($msg));
798 $response->addJSON(
799 'sql_query',
800 PMA\libraries\Util::getMessage($msg, $sql_query, 'success')
802 } else if ($result == false) {
803 $response = PMA\libraries\Response::getInstance();
804 $response->setRequestStatus(false);
805 $response->addJSON('message', PMA\libraries\Message::error($msg));
806 } else {
807 $active_page = $goto;
808 include '' . $goto;
811 // If there is request for ROLLBACK in the end.
812 if (isset($_REQUEST['rollback_query'])) {
813 $GLOBALS['dbi']->query('ROLLBACK');