Translated using Weblate (Dutch)
[phpmyadmin.git] / import.php
bloba6d4a5f11756420d02ce7f389b41bac303bfe024
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 */
9 /**
10 * Get the variables sent or posted to this script and a core script
12 require_once 'libraries/common.inc.php';
13 require_once 'libraries/sql.lib.php';
14 require_once 'libraries/bookmark.lib.php';
15 require_once 'libraries/Console.class.php';
16 //require_once 'libraries/display_import_functions.lib.php';
18 if (isset($_REQUEST['show_as_php'])) {
19 $GLOBALS['show_as_php'] = $_REQUEST['show_as_php'];
22 // Import functions.
23 require_once 'libraries/import.lib.php';
25 // If there is a request to 'Simulate DML'.
26 if (isset($_REQUEST['simulate_dml'])) {
27 PMA_handleSimulateDMLRequest();
28 exit;
31 // If it's a refresh console bookmarks request
32 if (isset($_REQUEST['console_bookmark_refresh'])) {
33 $response = PMA_Response::getInstance();
34 $response->addJSON(
35 'console_message_bookmark', PMA_Console::getBookmarkContent()
37 exit;
39 // If it's a console bookmark add request
40 if (isset($_REQUEST['console_bookmark_add'])) {
41 $response = PMA_Response::getInstance();
42 if (isset($_REQUEST['label']) && isset($_REQUEST['db'])
43 && isset($_REQUEST['bookmark_query']) && isset($_REQUEST['shared'])
44 ) {
45 $cfgBookmark = PMA_Bookmark_getParams();
46 $bookmarkFields = array(
47 'bkm_database' => $_REQUEST['db'],
48 'bkm_user' => $cfgBookmark['user'],
49 'bkm_sql_query' => urlencode($_REQUEST['bookmark_query']),
50 'bkm_label' => $_REQUEST['label']
52 $isShared = ($_REQUEST['shared'] == 'true' ? true : false);
53 if (PMA_Bookmark_save($bookmarkFields, $isShared)) {
54 $response->addJSON('message', __('Succeeded'));
55 $response->addJSON('data', $bookmarkFields);
56 $response->addJSON('isShared', $isShared);
57 } else {
58 $response->addJSON('message', __('Failed'));
60 die();
61 } else {
62 $response->addJSON('message', __('Incomplete params'));
63 die();
67 /**
68 * Sets globals from $_POST
70 $post_params = array(
71 'bkm_label',
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',
80 'skip_queries',
81 'local_import_file'
84 // TODO: adapt full list of allowed parameters, as in export.php
85 foreach ($post_params as $one_post_param) {
86 if (isset($_POST[$one_post_param])) {
87 $GLOBALS[$one_post_param] = $_POST[$one_post_param];
91 // reset import messages for ajax request
92 $_SESSION['Import_message']['message'] = null;
93 $_SESSION['Import_message']['go_back_url'] = null;
94 // default values
95 $GLOBALS['reload'] = false;
97 // Use to identify current cycle is executing
98 // a multiquery statement or stored routine
99 if (!isset($_SESSION['is_multi_query'])) {
100 $_SESSION['is_multi_query'] = false;
103 // Are we just executing plain query or sql file?
104 // (eg. non import, but query box/window run)
105 if (! empty($sql_query)) {
106 // run SQL query
107 $import_text = $sql_query;
108 $import_type = 'query';
109 $format = 'sql';
110 $_SESSION['sql_from_query_box'] = true;
112 // If there is a request to ROLLBACK when finished.
113 if (isset($_REQUEST['rollback_query'])) {
114 PMA_handleRollbackRequest($import_text);
117 // refresh navigation and main panels
118 if (preg_match('/^(DROP)\s+(VIEW|TABLE|DATABASE|SCHEMA)\s+/i', $sql_query)) {
119 $GLOBALS['reload'] = true;
122 // refresh navigation panel only
123 if (preg_match(
124 '/^(CREATE|ALTER)\s+(VIEW|TABLE|DATABASE|SCHEMA)\s+/i',
125 $sql_query
126 )) {
127 $ajax_reload = array('reload' => true);
130 // do a dynamic reload if table is RENAMED
131 // (by sending the instruction to the AJAX response handler)
132 if (preg_match(
133 '/^RENAME\s+TABLE\s+(.*?)\s+TO\s+(.*?)($|;|\s)/i',
134 $sql_query,
135 $rename_table_names
136 )) {
137 $ajax_reload = array('reload' => true);
138 $ajax_reload['table_name'] = PMA_Util::unQuote($rename_table_names[2]);
141 $sql_query = '';
142 } elseif (! empty($sql_localfile)) {
143 // run SQL file on server
144 $local_import_file = $sql_localfile;
145 $import_type = 'queryfile';
146 $format = 'sql';
147 unset($sql_localfile);
148 } elseif (! empty($sql_file)) {
149 // run uploaded SQL file
150 $import_file = $sql_file;
151 $import_type = 'queryfile';
152 $format = 'sql';
153 unset($sql_file);
154 } elseif (! empty($_REQUEST['id_bookmark'])) {
155 // run bookmark
156 $import_type = 'query';
157 $format = 'sql';
160 // If we didn't get any parameters, either user called this directly, or
161 // upload limit has been reached, let's assume the second possibility.
162 if ($_POST == array() && $_GET == array()) {
163 $message = PMA_Message::error(
164 __('You probably tried to upload a file that is too large. Please refer to %sdocumentation%s for a workaround for this limit.')
166 $message->addParam('[doc@faq1-16]');
167 $message->addParam('[/doc]');
169 // so we can obtain the message
170 $_SESSION['Import_message']['message'] = $message->getDisplay();
171 $_SESSION['Import_message']['go_back_url'] = $GLOBALS['goto'];
173 $message->display();
174 exit; // the footer is displayed automatically
177 // Add console message id to response output
178 if (isset($_POST['console_message_id'])) {
179 $response = PMA_Response::getInstance();
180 $response->addJSON('console_message_id', $_POST['console_message_id']);
184 * Sets globals from $_POST patterns, for import plugins
185 * We only need to load the selected plugin
188 if (! in_array(
189 $format,
190 array(
191 'csv',
192 'ldi',
193 'mediawiki',
194 'ods',
195 'shp',
196 'sql',
197 'xml'
201 // this should not happen for a normal user
202 // but only during an attack
203 PMA_fatalError('Incorrect format parameter');
206 $post_patterns = array(
207 '/^force_file_/',
208 '/^' . $format . '_/'
211 PMA_setPostAsGlobal($post_patterns);
213 // Check needed parameters
214 PMA_Util::checkParameters(array('import_type', 'format'));
216 // We don't want anything special in format
217 $format = PMA_securePath($format);
218 /** @var PMA_String $pmaString */
219 $pmaString = $GLOBALS['PMA_String'];
221 // Create error and goto url
222 if ($import_type == 'table') {
223 $err_url = 'tbl_import.php' . PMA_URL_getCommon(
224 array(
225 'db' => $db, 'table' => $table
228 $_SESSION['Import_message']['go_back_url'] = $err_url;
229 $goto = 'tbl_import.php';
230 } elseif ($import_type == 'database') {
231 $err_url = 'db_import.php' . PMA_URL_getCommon(array('db' => $db));
232 $_SESSION['Import_message']['go_back_url'] = $err_url;
233 $goto = 'db_import.php';
234 } elseif ($import_type == 'server') {
235 $err_url = 'server_import.php' . PMA_URL_getCommon();
236 $_SESSION['Import_message']['go_back_url'] = $err_url;
237 $goto = 'server_import.php';
238 } else {
239 if (empty($goto) || !preg_match('@^(server|db|tbl)(_[a-z]*)*\.php$@i', $goto)) {
240 if (/*overload*/mb_strlen($table) && /*overload*/mb_strlen($db)) {
241 $goto = 'tbl_structure.php';
242 } elseif (/*overload*/mb_strlen($db)) {
243 $goto = 'db_structure.php';
244 } else {
245 $goto = 'server_sql.php';
248 if (/*overload*/mb_strlen($table) && /*overload*/mb_strlen($db)) {
249 $common = PMA_URL_getCommon(array('db' => $db, 'table' => $table));
250 } elseif (/*overload*/mb_strlen($db)) {
251 $common = PMA_URL_getCommon(array('db' => $db));
252 } else {
253 $common = PMA_URL_getCommon();
255 $err_url = $goto . $common
256 . (preg_match('@^tbl_[a-z]*\.php$@', $goto)
257 ? '&amp;table=' . htmlspecialchars($table)
258 : '');
259 $_SESSION['Import_message']['go_back_url'] = $err_url;
261 // Avoid setting selflink to 'import.php'
262 // problem similar to bug 4276
263 if (basename($_SERVER['SCRIPT_NAME']) === 'import.php') {
264 $_SERVER['SCRIPT_NAME'] = $goto;
268 if (/*overload*/mb_strlen($db)) {
269 $GLOBALS['dbi']->selectDb($db);
272 @set_time_limit($cfg['ExecTimeLimit']);
273 if (! empty($cfg['MemoryLimit'])) {
274 @ini_set('memory_limit', $cfg['MemoryLimit']);
277 $timestamp = time();
278 if (isset($_REQUEST['allow_interrupt'])) {
279 $maximum_time = ini_get('max_execution_time');
280 } else {
281 $maximum_time = 0;
284 // set default values
285 $timeout_passed = false;
286 $error = false;
287 $read_multiply = 1;
288 $finished = false;
289 $offset = 0;
290 $max_sql_len = 0;
291 $file_to_unlink = '';
292 $sql_query = '';
293 $sql_query_disabled = false;
294 $go_sql = false;
295 $executed_queries = 0;
296 $run_query = true;
297 $charset_conversion = false;
298 $reset_charset = false;
299 $bookmark_created = false;
301 // Bookmark Support: get a query back from bookmark if required
302 if (! empty($_REQUEST['id_bookmark'])) {
303 $id_bookmark = (int)$_REQUEST['id_bookmark'];
304 include_once 'libraries/bookmark.lib.php';
305 switch ($_REQUEST['action_bookmark']) {
306 case 0: // bookmarked query that have to be run
307 $import_text = PMA_Bookmark_get(
308 $db,
309 $id_bookmark,
310 'id',
311 isset($_REQUEST['action_bookmark_all'])
313 if (! empty($_REQUEST['bookmark_variable'])) {
314 $import_text = PMA_Bookmark_applyVariables(
315 $import_text
319 // refresh navigation and main panels
320 if (preg_match(
321 '/^(DROP)\s+(VIEW|TABLE|DATABASE|SCHEMA)\s+/i',
322 $import_text
323 )) {
324 $GLOBALS['reload'] = true;
327 // refresh navigation panel only
328 if (preg_match(
329 '/^(CREATE|ALTER)\s+(VIEW|TABLE|DATABASE|SCHEMA)\s+/i',
330 $import_text
333 if (! isset($ajax_reload)) {
334 $ajax_reload = array();
336 $ajax_reload['reload'] = true;
338 break;
339 case 1: // bookmarked query that have to be displayed
340 $import_text = PMA_Bookmark_get($db, $id_bookmark);
341 if ($GLOBALS['is_ajax_request'] == true) {
342 $message = PMA_Message::success(__('Showing bookmark'));
343 $response = PMA_Response::getInstance();
344 $response->isSuccess($message->isSuccess());
345 $response->addJSON('message', $message);
346 $response->addJSON('sql_query', $import_text);
347 $response->addJSON('action_bookmark', $_REQUEST['action_bookmark']);
348 exit;
349 } else {
350 $run_query = false;
352 break;
353 case 2: // bookmarked query that have to be deleted
354 $import_text = PMA_Bookmark_get($db, $id_bookmark);
355 PMA_Bookmark_delete($id_bookmark);
356 if ($GLOBALS['is_ajax_request'] == true) {
357 $message = PMA_Message::success(__('The bookmark has been deleted.'));
358 $response = PMA_Response::getInstance();
359 $response->isSuccess($message->isSuccess());
360 $response->addJSON('message', $message);
361 $response->addJSON('action_bookmark', $_REQUEST['action_bookmark']);
362 $response->addJSON('id_bookmark', $id_bookmark);
363 exit;
364 } else {
365 $run_query = false;
366 $error = true; // this is kind of hack to skip processing the query
368 break;
370 } // end bookmarks reading
372 // Do no run query if we show PHP code
373 if (isset($GLOBALS['show_as_php'])) {
374 $run_query = false;
375 $go_sql = true;
378 // We can not read all at once, otherwise we can run out of memory
379 $memory_limit = trim(@ini_get('memory_limit'));
380 // 2 MB as default
381 if (empty($memory_limit)) {
382 $memory_limit = 2 * 1024 * 1024;
384 // In case no memory limit we work on 10MB chunks
385 if ($memory_limit == -1) {
386 $memory_limit = 10 * 1024 * 1024;
389 // Calculate value of the limit
390 $memoryUnit = /*overload*/mb_strtolower(substr($memory_limit, -1));
391 if ('m' == $memoryUnit) {
392 $memory_limit = (int)substr($memory_limit, 0, -1) * 1024 * 1024;
393 } elseif ('k' == $memoryUnit) {
394 $memory_limit = (int)substr($memory_limit, 0, -1) * 1024;
395 } elseif ('g' == $memoryUnit) {
396 $memory_limit = (int)substr($memory_limit, 0, -1) * 1024 * 1024 * 1024;
397 } else {
398 $memory_limit = (int)$memory_limit;
401 // Just to be sure, there might be lot of memory needed for uncompression
402 $read_limit = $memory_limit / 8;
404 // handle filenames
405 if (isset($_FILES['import_file'])) {
406 $import_file = $_FILES['import_file']['tmp_name'];
408 if (! empty($local_import_file) && ! empty($cfg['UploadDir'])) {
410 // sanitize $local_import_file as it comes from a POST
411 $local_import_file = PMA_securePath($local_import_file);
413 $import_file = PMA_Util::userDir($cfg['UploadDir'])
414 . $local_import_file;
416 } elseif (empty($import_file) || ! is_uploaded_file($import_file)) {
417 $import_file = 'none';
420 // Do we have file to import?
422 if ($import_file != 'none' && ! $error) {
423 // work around open_basedir and other limitations
424 $open_basedir = @ini_get('open_basedir');
426 // If we are on a server with open_basedir, we must move the file
427 // before opening it.
429 if (! empty($open_basedir)) {
430 $tmp_subdir = ini_get('upload_tmp_dir');
431 if (empty($tmp_subdir)) {
432 $tmp_subdir = sys_get_temp_dir();
434 $tmp_subdir = rtrim($tmp_subdir, DIRECTORY_SEPARATOR);
435 if (is_writable($tmp_subdir)) {
436 $import_file_new = $tmp_subdir . DIRECTORY_SEPARATOR
437 . basename($import_file) . uniqid();
438 if (move_uploaded_file($import_file, $import_file_new)) {
439 $import_file = $import_file_new;
440 $file_to_unlink = $import_file_new;
443 $size = filesize($import_file);
444 } else {
446 // If the php.ini is misconfigured (eg. there is no /tmp access defined
447 // with open_basedir), $tmp_subdir won't be writable and the user gets
448 // a 'File could not be read!' error (at PMA_detectCompression), which
449 // is not too meaningful. Show a meaningful error message to the user
450 // instead.
452 $message = PMA_Message::error(
453 __('Uploaded file cannot be moved, because the server has open_basedir enabled without access to the %s directory (for temporary files).')
455 $message->addParam($tmp_subdir);
456 PMA_stopImport($message);
461 * Handle file compression
462 * @todo duplicate code exists in File.class.php
464 $compression = PMA_detectCompression($import_file);
465 if ($compression === false) {
466 $message = PMA_Message::error(__('File could not be read!'));
467 PMA_stopImport($message); //Contains an 'exit'
470 switch ($compression) {
471 case 'application/bzip2':
472 if ($cfg['BZipDump'] && @function_exists('bzopen')) {
473 $import_handle = @bzopen($import_file, 'r');
474 } else {
475 $message = PMA_Message::error(
476 __('You attempted to load file with unsupported compression (%s). Either support for it is not implemented or disabled by your configuration.')
478 $message->addParam($compression);
479 PMA_stopImport($message);
481 break;
482 case 'application/gzip':
483 if ($cfg['GZipDump'] && @function_exists('gzopen')) {
484 $import_handle = @gzopen($import_file, 'r');
485 } else {
486 $message = PMA_Message::error(
487 __('You attempted to load file with unsupported compression (%s). Either support for it is not implemented or disabled by your configuration.')
489 $message->addParam($compression);
490 PMA_stopImport($message);
492 break;
493 case 'application/zip':
494 if ($cfg['ZipDump'] && @function_exists('zip_open')) {
496 * Load interface for zip extension.
498 include_once 'libraries/zip_extension.lib.php';
499 $zipResult = PMA_getZipContents($import_file);
500 if (! empty($zipResult['error'])) {
501 $message = PMA_Message::rawError($zipResult['error']);
502 PMA_stopImport($message);
503 } else {
504 $import_text = $zipResult['data'];
506 } else {
507 $message = PMA_Message::error(
508 __('You attempted to load file with unsupported compression (%s). Either support for it is not implemented or disabled by your configuration.')
510 $message->addParam($compression);
511 PMA_stopImport($message);
513 break;
514 case 'none':
515 $import_handle = @fopen($import_file, 'r');
516 break;
517 default:
518 $message = PMA_Message::error(
519 __('You attempted to load file with unsupported compression (%s). Either support for it is not implemented or disabled by your configuration.')
521 $message->addParam($compression);
522 PMA_stopImport($message);
523 break;
525 // use isset() because zip compression type does not use a handle
526 if (! $error && isset($import_handle) && $import_handle === false) {
527 $message = PMA_Message::error(__('File could not be read!'));
528 PMA_stopImport($message);
530 } elseif (! $error) {
531 if (! isset($import_text) || empty($import_text)) {
532 $message = PMA_Message::error(
533 __('No data was received to import. Either no file name was submitted, or the file size exceeded the maximum size permitted by your PHP configuration. See [doc@faq1-16]FAQ 1.16[/doc].')
535 PMA_stopImport($message);
539 // so we can obtain the message
540 //$_SESSION['Import_message'] = $message->getDisplay();
542 // Convert the file's charset if necessary
543 if ($GLOBALS['PMA_recoding_engine'] != PMA_CHARSET_NONE && isset($charset_of_file)) {
544 if ($charset_of_file != 'utf-8') {
545 $charset_conversion = true;
547 } elseif (isset($charset_of_file) && $charset_of_file != 'utf-8') {
548 if (PMA_DRIZZLE) {
549 // Drizzle doesn't support other character sets,
550 // so we can't fallback to SET NAMES - throw an error
551 $message = PMA_Message::error(
553 'Cannot convert file\'s character'
554 . ' set without character set conversion library!'
557 PMA_stopImport($message);
558 } else {
559 $GLOBALS['dbi']->query('SET NAMES \'' . $charset_of_file . '\'');
560 // We can not show query in this case, it is in different charset
561 $sql_query_disabled = true;
562 $reset_charset = true;
566 // Something to skip?
567 if (! $error && isset($skip)) {
568 $original_skip = $skip;
569 while ($skip > 0) {
570 PMA_importGetNextChunk($skip < $read_limit ? $skip : $read_limit);
571 // Disable read progressivity, otherwise we eat all memory!
572 $read_multiply = 1;
573 $skip -= $read_limit;
575 unset($skip);
578 // This array contain the data like numberof valid sql queries in the statement
579 // and complete valid sql statement (which affected for rows)
580 $sql_data = array('valid_sql' => array(), 'valid_queries' => 0);
582 if (! $error) {
583 // Check for file existence
584 include_once "libraries/plugin_interface.lib.php";
585 $import_plugin = PMA_getPlugin(
586 "import",
587 $format,
588 'libraries/plugins/import/',
589 $import_type
591 if ($import_plugin == null) {
592 $message = PMA_Message::error(
593 __('Could not load import plugins, please check your installation!')
595 PMA_stopImport($message);
596 } else {
597 // Do the real import
598 if (isset($_REQUEST['disable_foreign_keys'])) {
600 $default_fk_check_value = $GLOBALS['dbi']->fetchValue(
601 "SHOW VARIABLES LIKE 'foreign_key_checks';", 0, 1
602 ) == 'ON';
604 try {
605 if ($default_fk_check_value) {
606 $GLOBALS['dbi']->tryQuery("SET FOREIGN_KEY_CHECKS = 0;");
608 $import_plugin->doImport($sql_data);
609 if ($default_fk_check_value) {
610 $GLOBALS['dbi']->tryQuery('SET FOREIGN_KEY_CHECKS = 1;');
612 } catch (Exception $e) {
613 if ($default_fk_check_value) {
614 $GLOBALS['dbi']->tryQuery('SET FOREIGN_KEY_CHECKS = 1;');
616 throw $e;
618 } else {
619 $import_plugin->doImport($sql_data);
624 if (! empty($import_handle)) {
625 fclose($import_handle);
628 // Cleanup temporary file
629 if ($file_to_unlink != '') {
630 unlink($file_to_unlink);
633 // Reset charset back, if we did some changes
634 if ($reset_charset) {
635 $GLOBALS['dbi']->query('SET CHARACTER SET utf8');
636 $GLOBALS['dbi']->query(
637 'SET SESSION collation_connection =\'' . $collation_connection . '\''
641 // Show correct message
642 if (! empty($id_bookmark) && $_REQUEST['action_bookmark'] == 2) {
643 $message = PMA_Message::success(__('The bookmark has been deleted.'));
644 $display_query = $import_text;
645 $error = false; // unset error marker, it was used just to skip processing
646 } elseif (! empty($id_bookmark) && $_REQUEST['action_bookmark'] == 1) {
647 $message = PMA_Message::notice(__('Showing bookmark'));
648 } elseif ($bookmark_created) {
649 $special_message = '[br]' . sprintf(
650 __('Bookmark %s has been created.'),
651 htmlspecialchars($bkm_label)
653 } elseif ($finished && ! $error) {
654 if ($import_type == 'query') {
655 $message = PMA_Message::success();
656 } else {
657 $message = PMA_Message::success(
658 '<em>'
659 . __('Import has been successfully finished, %d queries executed.')
660 . '</em>'
662 $message->addParam($executed_queries);
664 if ($import_notice) {
665 $message->addString($import_notice);
667 if (isset($local_import_file)) {
668 $message->addString('(' . htmlspecialchars($local_import_file) . ')');
669 } else {
670 $message->addString(
671 '(' . htmlspecialchars($_FILES['import_file']['name']) . ')'
677 // Did we hit timeout? Tell it user.
678 if ($timeout_passed) {
679 $importUrl = $err_url .= '&timeout_passed=1&offset=' . urlencode($GLOBALS['offset']);
680 if (isset($local_import_file)) {
681 $importUrl .= '&local_import_file=' . urlencode($local_import_file);
683 $message = PMA_Message::error(
685 'Script timeout passed, if you want to finish import,'
686 . ' please %sresubmit the same file%s and import will resume.'
689 $message->addParam('<a href="' . $importUrl . '">', false);
690 $message->addParam('</a>', false);
692 if ($offset == 0 || (isset($original_skip) && $original_skip == $offset)) {
693 $message->addString(
695 'However on last run no data has been parsed,'
696 . ' this usually means phpMyAdmin won\'t be able to'
697 . ' finish this import unless you increase php time limits.'
703 // if there is any message, copy it into $_SESSION as well,
704 // so we can obtain it by AJAX call
705 if (isset($message)) {
706 $_SESSION['Import_message']['message'] = $message->getDisplay();
708 // Parse and analyze the query, for correct db and table name
709 // in case of a query typed in the query window
710 // (but if the query is too large, in case of an imported file, the parser
711 // can choke on it so avoid parsing)
712 $sqlLength = /*overload*/mb_strlen($sql_query);
713 if ($sqlLength <= $GLOBALS['cfg']['MaxCharactersInDisplayedSQL']) {
714 include_once 'libraries/parse_analyze.inc.php';
717 // There was an error?
718 if (isset($my_die)) {
719 foreach ($my_die as $key => $die) {
720 PMA_Util::mysqlDie(
721 $die['error'], $die['sql'], false, $err_url, $error
726 if ($go_sql) {
728 if (! empty($sql_data) && ($sql_data['valid_queries'] > 1)) {
729 $_SESSION['is_multi_query'] = true;
730 $sql_queries = $sql_data['valid_sql'];
731 } else {
732 $sql_queries = array($sql_query);
735 $html_output = '';
736 foreach ($sql_queries as $sql_query) {
737 // parse sql query
738 include 'libraries/parse_analyze.inc.php';
740 $html_output .= PMA_executeQueryAndGetQueryResponse(
741 $analyzed_sql_results, false, $db, $table, null,
742 $sql_query, null, $analyzed_sql_results['is_affected'],
743 null, null, null, $goto, $pmaThemeImage,
744 null, null, null, $sql_query, null, null
748 if (!isset($ajax_reload)) {
749 $ajax_reload = array();
751 if (isset($table)) {
752 $ajax_reload['table_name'] = $table;
754 $response = PMA_Response::getInstance();
755 $response->addJSON('ajax_reload', $ajax_reload);
756 $response->addHTML($html_output);
757 exit();
759 } else if ($result) {
760 // Save a Bookmark with more than one queries (if Bookmark label given).
761 if (! empty($_POST['bkm_label']) && ! empty($import_text)) {
762 $cfgBookmark = PMA_Bookmark_getParams();
763 PMA_storeTheQueryAsBookmark(
764 $db, $cfgBookmark['user'],
765 $_REQUEST['sql_query'], $_POST['bkm_label'],
766 isset($_POST['bkm_replace']) ? $_POST['bkm_replace'] : null
770 $response = PMA_Response::getInstance();
771 $response->isSuccess(true);
772 $response->addJSON('message', PMA_Message::success($msg));
773 $response->addJSON(
774 'sql_query',
775 PMA_Util::getMessage($msg, $sql_query, 'success')
777 } else if ($result == false) {
778 $response = PMA_Response::getInstance();
779 $response->isSuccess(false);
780 $response->addJSON('message', PMA_Message::error($msg));
781 } else {
782 $active_page = $goto;
783 include '' . $goto;
786 // If there is request for ROLLBACK in the end.
787 if (isset($_REQUEST['rollback_query'])) {
788 $GLOBALS['dbi']->query('ROLLBACK');