import.php 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676
  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
  5. *
  6. * @package PhpMyAdmin
  7. */
  8. /**
  9. * Get the variables sent or posted to this script and a core script
  10. */
  11. require_once 'libraries/common.inc.php';
  12. require_once 'libraries/sql.lib.php';
  13. require_once 'libraries/bookmark.lib.php';
  14. //require_once 'libraries/display_import_functions.lib.php';
  15. if (isset($_REQUEST['show_as_php'])) {
  16. $GLOBALS['show_as_php'] = $_REQUEST['show_as_php'];
  17. }
  18. /**
  19. * Sets globals from $_POST
  20. */
  21. $post_params = array(
  22. 'action_bookmark',
  23. 'allow_interrupt',
  24. 'bkm_label',
  25. 'bookmark_variable',
  26. 'charset_of_file',
  27. 'format',
  28. 'id_bookmark',
  29. 'import_type',
  30. 'is_js_confirmed',
  31. 'MAX_FILE_SIZE',
  32. 'message_to_show',
  33. 'noplugin',
  34. 'skip_queries',
  35. 'local_import_file'
  36. );
  37. // TODO: adapt full list of allowed parameters, as in export.php
  38. foreach ($post_params as $one_post_param) {
  39. if (isset($_POST[$one_post_param])) {
  40. $GLOBALS[$one_post_param] = $_POST[$one_post_param];
  41. }
  42. }
  43. // reset import messages for ajax request
  44. $_SESSION['Import_message']['message'] = null;
  45. $_SESSION['Import_message']['go_back_url'] = null;
  46. // default values
  47. $GLOBALS['reload'] = false;
  48. // Use to identify curren cycle is executing
  49. // a multiquery statement or stored routine
  50. if (!isset($_SESSION['is_multi_query'])) {
  51. $_SESSION['is_multi_query'] = false;
  52. }
  53. // Are we just executing plain query or sql file?
  54. // (eg. non import, but query box/window run)
  55. if (! empty($sql_query)) {
  56. // run SQL query
  57. $import_text = $sql_query;
  58. $import_type = 'query';
  59. $format = 'sql';
  60. // refresh navigation and main panels
  61. if (preg_match('/^(DROP)\s+(VIEW|TABLE|DATABASE|SCHEMA)\s+/i', $sql_query)) {
  62. $GLOBALS['reload'] = true;
  63. }
  64. // refresh navigation panel only
  65. if (preg_match(
  66. '/^(CREATE|ALTER)\s+(VIEW|TABLE|DATABASE|SCHEMA)\s+/i',
  67. $sql_query
  68. )) {
  69. $ajax_reload['reload'] = true;
  70. }
  71. // do a dynamic reload if table is RENAMED
  72. // (by sending the instruction to the AJAX response handler)
  73. if (preg_match(
  74. '/^RENAME\s+TABLE\s+(.*?)\s+TO\s+(.*?)($|;|\s)/i',
  75. $sql_query,
  76. $rename_table_names
  77. )) {
  78. $ajax_reload['table_name'] = PMA_Util::unQuote($rename_table_names[2]);
  79. $ajax_reload['reload'] = true;
  80. }
  81. $sql_query = '';
  82. } elseif (! empty($sql_localfile)) {
  83. // run SQL file on server
  84. $local_import_file = $sql_localfile;
  85. $import_type = 'queryfile';
  86. $format = 'sql';
  87. unset($sql_localfile);
  88. } elseif (! empty($sql_file)) {
  89. // run uploaded SQL file
  90. $import_file = $sql_file;
  91. $import_type = 'queryfile';
  92. $format = 'sql';
  93. unset($sql_file);
  94. } elseif (! empty($id_bookmark)) {
  95. // run bookmark
  96. $import_type = 'query';
  97. $format = 'sql';
  98. }
  99. // If we didn't get any parameters, either user called this directly, or
  100. // upload limit has been reached, let's assume the second possibility.
  101. ;
  102. if ($_POST == array() && $_GET == array()) {
  103. $message = PMA_Message::error(
  104. __('You probably tried to upload a file that is too large. Please refer to %sdocumentation%s for a workaround for this limit.')
  105. );
  106. $message->addParam('[doc@faq1-16]');
  107. $message->addParam('[/doc]');
  108. // so we can obtain the message
  109. $_SESSION['Import_message']['message'] = $message->getDisplay();
  110. $_SESSION['Import_message']['go_back_url'] = $goto;
  111. $message->display();
  112. exit; // the footer is displayed automatically
  113. }
  114. /**
  115. * Sets globals from $_POST patterns, for import plugins
  116. * We only need to load the selected plugin
  117. */
  118. if (! in_array(
  119. $format,
  120. array(
  121. 'csv',
  122. 'ldi',
  123. 'mediawiki',
  124. 'ods',
  125. 'shp',
  126. 'sql',
  127. 'xml'
  128. )
  129. )
  130. ) {
  131. // this should not happen for a normal user
  132. // but only during an attack
  133. PMA_fatalError('Incorrect format parameter');
  134. }
  135. $post_patterns = array(
  136. '/^force_file_/',
  137. '/^' . $format . '_/'
  138. );
  139. foreach (array_keys($_POST) as $post_key) {
  140. foreach ($post_patterns as $one_post_pattern) {
  141. if (preg_match($one_post_pattern, $post_key)) {
  142. $GLOBALS[$post_key] = $_POST[$post_key];
  143. }
  144. }
  145. }
  146. // Check needed parameters
  147. PMA_Util::checkParameters(array('import_type', 'format'));
  148. // We don't want anything special in format
  149. $format = PMA_securePath($format);
  150. // Import functions
  151. require_once 'libraries/import.lib.php';
  152. // Create error and goto url
  153. if ($import_type == 'table') {
  154. $err_url = 'tbl_import.php?' . PMA_URL_getCommon($db, $table);
  155. $_SESSION['Import_message']['go_back_url'] = $err_url;
  156. $goto = 'tbl_import.php';
  157. } elseif ($import_type == 'database') {
  158. $err_url = 'db_import.php?' . PMA_URL_getCommon($db);
  159. $_SESSION['Import_message']['go_back_url'] = $err_url;
  160. $goto = 'db_import.php';
  161. } elseif ($import_type == 'server') {
  162. $err_url = 'server_import.php?' . PMA_URL_getCommon();
  163. $_SESSION['Import_message']['go_back_url'] = $err_url;
  164. $goto = 'server_import.php';
  165. } else {
  166. if (empty($goto) || !preg_match('@^(server|db|tbl)(_[a-z]*)*\.php$@i', $goto)) {
  167. if (strlen($table) && strlen($db)) {
  168. $goto = 'tbl_structure.php';
  169. } elseif (strlen($db)) {
  170. $goto = 'db_structure.php';
  171. } else {
  172. $goto = 'server_sql.php';
  173. }
  174. }
  175. if (strlen($table) && strlen($db)) {
  176. $common = PMA_URL_getCommon($db, $table);
  177. } elseif (strlen($db)) {
  178. $common = PMA_URL_getCommon($db);
  179. } else {
  180. $common = PMA_URL_getCommon();
  181. }
  182. $err_url = $goto . '?' . $common
  183. . (preg_match('@^tbl_[a-z]*\.php$@', $goto)
  184. ? '&amp;table=' . htmlspecialchars($table)
  185. : '');
  186. $_SESSION['Import_message']['go_back_url'] = $err_url;
  187. }
  188. // Avoid setting selflink to 'import.php'
  189. // problem similar to bug 4276
  190. if (basename($_SERVER['SCRIPT_NAME']) === 'import.php') {
  191. $_SERVER['SCRIPT_NAME'] = $goto;
  192. }
  193. if (strlen($db)) {
  194. $GLOBALS['dbi']->selectDb($db);
  195. }
  196. @set_time_limit($cfg['ExecTimeLimit']);
  197. if (! empty($cfg['MemoryLimit'])) {
  198. @ini_set('memory_limit', $cfg['MemoryLimit']);
  199. }
  200. $timestamp = time();
  201. if (isset($allow_interrupt)) {
  202. $maximum_time = ini_get('max_execution_time');
  203. } else {
  204. $maximum_time = 0;
  205. }
  206. // set default values
  207. $timeout_passed = false;
  208. $error = false;
  209. $read_multiply = 1;
  210. $finished = false;
  211. $offset = 0;
  212. $max_sql_len = 0;
  213. $file_to_unlink = '';
  214. $sql_query = '';
  215. $sql_query_disabled = false;
  216. $go_sql = false;
  217. $executed_queries = 0;
  218. $run_query = true;
  219. $charset_conversion = false;
  220. $reset_charset = false;
  221. $bookmark_created = false;
  222. // Bookmark Support: get a query back from bookmark if required
  223. if (! empty($id_bookmark)) {
  224. $id_bookmark = (int)$id_bookmark;
  225. include_once 'libraries/bookmark.lib.php';
  226. switch ($action_bookmark) {
  227. case 0: // bookmarked query that have to be run
  228. $import_text = PMA_Bookmark_get(
  229. $db,
  230. $id_bookmark,
  231. 'id',
  232. isset($action_bookmark_all)
  233. );
  234. if (isset($bookmark_variable) && ! empty($bookmark_variable)) {
  235. $import_text = preg_replace(
  236. '|/\*(.*)\[VARIABLE\](.*)\*/|imsU',
  237. '${1}' . PMA_Util::sqlAddSlashes($bookmark_variable) . '${2}',
  238. $import_text
  239. );
  240. }
  241. // refresh navigation and main panels
  242. if (preg_match(
  243. '/^(DROP)\s+(VIEW|TABLE|DATABASE|SCHEMA)\s+/i',
  244. $import_text
  245. )) {
  246. $GLOBALS['reload'] = true;
  247. }
  248. // refresh navigation panel only
  249. if (preg_match(
  250. '/^(CREATE|ALTER)\s+(VIEW|TABLE|DATABASE|SCHEMA)\s+/i',
  251. $import_text
  252. )
  253. ) {
  254. $ajax_reload['reload'] = true;
  255. }
  256. break;
  257. case 1: // bookmarked query that have to be displayed
  258. $import_text = PMA_Bookmark_get($db, $id_bookmark);
  259. if ($GLOBALS['is_ajax_request'] == true) {
  260. $message = PMA_Message::success(__('Showing bookmark'));
  261. $response = PMA_Response::getInstance();
  262. $response->isSuccess($message->isSuccess());
  263. $response->addJSON('message', $message);
  264. $response->addJSON('sql_query', $import_text);
  265. $response->addJSON('action_bookmark', $action_bookmark);
  266. exit;
  267. } else {
  268. $run_query = false;
  269. }
  270. break;
  271. case 2: // bookmarked query that have to be deleted
  272. $import_text = PMA_Bookmark_get($db, $id_bookmark);
  273. PMA_Bookmark_delete($id_bookmark);
  274. if ($GLOBALS['is_ajax_request'] == true) {
  275. $message = PMA_Message::success(__('The bookmark has been deleted.'));
  276. $response = PMA_Response::getInstance();
  277. $response->isSuccess($message->isSuccess());
  278. $response->addJSON('message', $message);
  279. $response->addJSON('action_bookmark', $action_bookmark);
  280. $response->addJSON('id_bookmark', $id_bookmark);
  281. exit;
  282. } else {
  283. $run_query = false;
  284. $error = true; // this is kind of hack to skip processing the query
  285. }
  286. break;
  287. }
  288. } // end bookmarks reading
  289. // Do no run query if we show PHP code
  290. if (isset($GLOBALS['show_as_php'])) {
  291. $run_query = false;
  292. $go_sql = true;
  293. }
  294. // We can not read all at once, otherwise we can run out of memory
  295. $memory_limit = trim(@ini_get('memory_limit'));
  296. // 2 MB as default
  297. if (empty($memory_limit)) {
  298. $memory_limit = 2 * 1024 * 1024;
  299. }
  300. // In case no memory limit we work on 10MB chunks
  301. if ($memory_limit == -1) {
  302. $memory_limit = 10 * 1024 * 1024;
  303. }
  304. // Calculate value of the limit
  305. if (strtolower(substr($memory_limit, -1)) == 'm') {
  306. $memory_limit = (int)substr($memory_limit, 0, -1) * 1024 * 1024;
  307. } elseif (strtolower(substr($memory_limit, -1)) == 'k') {
  308. $memory_limit = (int)substr($memory_limit, 0, -1) * 1024;
  309. } elseif (strtolower(substr($memory_limit, -1)) == 'g') {
  310. $memory_limit = (int)substr($memory_limit, 0, -1) * 1024 * 1024 * 1024;
  311. } else {
  312. $memory_limit = (int)$memory_limit;
  313. }
  314. // Just to be sure, there might be lot of memory needed for uncompression
  315. $read_limit = $memory_limit / 8;
  316. // handle filenames
  317. if (isset($_FILES['import_file'])) {
  318. $import_file = $_FILES['import_file']['tmp_name'];
  319. }
  320. if (! empty($local_import_file) && ! empty($cfg['UploadDir'])) {
  321. // sanitize $local_import_file as it comes from a POST
  322. $local_import_file = PMA_securePath($local_import_file);
  323. $import_file = PMA_Util::userDir($cfg['UploadDir'])
  324. . $local_import_file;
  325. } elseif (empty($import_file) || ! is_uploaded_file($import_file)) {
  326. $import_file = 'none';
  327. }
  328. // Do we have file to import?
  329. if ($import_file != 'none' && ! $error) {
  330. // work around open_basedir and other limitations
  331. $open_basedir = @ini_get('open_basedir');
  332. // If we are on a server with open_basedir, we must move the file
  333. // before opening it.
  334. if (! empty($open_basedir)) {
  335. /**
  336. * @todo make use of the config's temp dir with fallback to the
  337. * system's tmp dir
  338. */
  339. $tmp_subdir = ini_get('upload_tmp_dir');
  340. if (empty($tmp_subdir)) {
  341. $tmp_subdir = sys_get_temp_dir();
  342. }
  343. if (is_writable($tmp_subdir)) {
  344. $import_file_new = $tmp_subdir . basename($import_file) . uniqid();
  345. if (move_uploaded_file($import_file, $import_file_new)) {
  346. $import_file = $import_file_new;
  347. $file_to_unlink = $import_file_new;
  348. }
  349. $size = filesize($import_file);
  350. } else {
  351. // If the php.ini is misconfigured (eg. there is no /tmp access defined
  352. // with open_basedir), $tmp_subdir won't be writable and the user gets
  353. // a 'File could not be read!' error (at PMA_detectCompression), which
  354. // is not too meaningful. Show a meaningful error message to the user
  355. // instead.
  356. $message = PMA_Message::error(
  357. __('Uploaded file cannot be moved, because the server has open_basedir enabled without access to the %s directory (for temporary files).')
  358. );
  359. $message->addParam($tmp_subdir);
  360. PMA_stopImport($message);
  361. }
  362. }
  363. /**
  364. * Handle file compression
  365. * @todo duplicate code exists in File.class.php
  366. */
  367. $compression = PMA_detectCompression($import_file);
  368. if ($compression === false) {
  369. $message = PMA_Message::error(__('File could not be read!'));
  370. PMA_stopImport($message);
  371. } else {
  372. switch ($compression) {
  373. case 'application/bzip2':
  374. if ($cfg['BZipDump'] && @function_exists('bzopen')) {
  375. $import_handle = @bzopen($import_file, 'r');
  376. } else {
  377. $message = PMA_Message::error(
  378. __('You attempted to load file with unsupported compression (%s). Either support for it is not implemented or disabled by your configuration.')
  379. );
  380. $message->addParam($compression);
  381. PMA_stopImport($message);
  382. }
  383. break;
  384. case 'application/gzip':
  385. if ($cfg['GZipDump'] && @function_exists('gzopen')) {
  386. $import_handle = @gzopen($import_file, 'r');
  387. } else {
  388. $message = PMA_Message::error(
  389. __('You attempted to load file with unsupported compression (%s). Either support for it is not implemented or disabled by your configuration.')
  390. );
  391. $message->addParam($compression);
  392. PMA_stopImport($message);
  393. }
  394. break;
  395. case 'application/zip':
  396. if ($cfg['ZipDump'] && @function_exists('zip_open')) {
  397. /**
  398. * Load interface for zip extension.
  399. */
  400. include_once 'libraries/zip_extension.lib.php';
  401. $zipResult = PMA_getZipContents($import_file);
  402. if (! empty($zipResult['error'])) {
  403. $message = PMA_Message::rawError($zipResult['error']);
  404. PMA_stopImport($message);
  405. } else {
  406. $import_text = $zipResult['data'];
  407. }
  408. } else {
  409. $message = PMA_Message::error(
  410. __('You attempted to load file with unsupported compression (%s). Either support for it is not implemented or disabled by your configuration.')
  411. );
  412. $message->addParam($compression);
  413. PMA_stopImport($message);
  414. }
  415. break;
  416. case 'none':
  417. $import_handle = @fopen($import_file, 'r');
  418. break;
  419. default:
  420. $message = PMA_Message::error(
  421. __('You attempted to load file with unsupported compression (%s). Either support for it is not implemented or disabled by your configuration.')
  422. );
  423. $message->addParam($compression);
  424. PMA_stopImport($message);
  425. break;
  426. }
  427. }
  428. // use isset() because zip compression type does not use a handle
  429. if (! $error && isset($import_handle) && $import_handle === false) {
  430. $message = PMA_Message::error(__('File could not be read!'));
  431. PMA_stopImport($message);
  432. }
  433. } elseif (! $error) {
  434. if (! isset($import_text) || empty($import_text)) {
  435. $message = PMA_Message::error(
  436. __('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].')
  437. );
  438. PMA_stopImport($message);
  439. }
  440. }
  441. // so we can obtain the message
  442. //$_SESSION['Import_message'] = $message->getDisplay();
  443. // Convert the file's charset if necessary
  444. if ($GLOBALS['PMA_recoding_engine'] != PMA_CHARSET_NONE && isset($charset_of_file)) {
  445. if ($charset_of_file != 'utf-8') {
  446. $charset_conversion = true;
  447. }
  448. } elseif (isset($charset_of_file) && $charset_of_file != 'utf8') {
  449. if (PMA_DRIZZLE) {
  450. // Drizzle doesn't support other character sets,
  451. // so we can't fallback to SET NAMES - throw an error
  452. $message = PMA_Message::error(
  453. __('Cannot convert file\'s character set without character set conversion library!')
  454. );
  455. PMA_stopImport($message);
  456. } else {
  457. $GLOBALS['dbi']->query('SET NAMES \'' . $charset_of_file . '\'');
  458. // We can not show query in this case, it is in different charset
  459. $sql_query_disabled = true;
  460. $reset_charset = true;
  461. }
  462. }
  463. // Something to skip?
  464. if (! $error && isset($skip)) {
  465. $original_skip = $skip;
  466. while ($skip > 0) {
  467. PMA_importGetNextChunk($skip < $read_limit ? $skip : $read_limit);
  468. // Disable read progressivity, otherwise we eat all memory!
  469. $read_multiply = 1;
  470. $skip -= $read_limit;
  471. }
  472. unset($skip);
  473. }
  474. // This array contain the data like numberof valid sql queries in the statement
  475. // and complete valid sql statement (which affected for rows)
  476. $sql_data = array('valid_sql' => array(), 'valid_queries' => 0);
  477. if (! $error) {
  478. // Check for file existance
  479. include_once "libraries/plugin_interface.lib.php";
  480. $import_plugin = PMA_getPlugin(
  481. "import",
  482. $format,
  483. 'libraries/plugins/import/',
  484. $import_type
  485. );
  486. if ($import_plugin == null) {
  487. $message = PMA_Message::error(
  488. __('Could not load import plugins, please check your installation!')
  489. );
  490. PMA_stopImport($message);
  491. } else {
  492. // Do the real import
  493. $import_plugin->doImport($sql_data);
  494. }
  495. }
  496. if (false !== $import_handle && null !== $import_handle) {
  497. fclose($import_handle);
  498. }
  499. // Cleanup temporary file
  500. if ($file_to_unlink != '') {
  501. unlink($file_to_unlink);
  502. }
  503. // Reset charset back, if we did some changes
  504. if ($reset_charset) {
  505. $GLOBALS['dbi']->query('SET CHARACTER SET utf8');
  506. $GLOBALS['dbi']->query(
  507. 'SET SESSION collation_connection =\'' . $collation_connection . '\''
  508. );
  509. }
  510. // Show correct message
  511. if (! empty($id_bookmark) && $action_bookmark == 2) {
  512. $message = PMA_Message::success(__('The bookmark has been deleted.'));
  513. $display_query = $import_text;
  514. $error = false; // unset error marker, it was used just to skip processing
  515. } elseif (! empty($id_bookmark) && $action_bookmark == 1) {
  516. $message = PMA_Message::notice(__('Showing bookmark'));
  517. } elseif ($bookmark_created) {
  518. $special_message = '[br]' . sprintf(
  519. __('Bookmark %s has been created.'),
  520. htmlspecialchars($bkm_label)
  521. );
  522. } elseif ($finished && ! $error) {
  523. if ($import_type == 'query') {
  524. $message = PMA_Message::success();
  525. } else {
  526. $message = PMA_Message::success(
  527. '<em>'
  528. . __('Import has been successfully finished, %d queries executed.')
  529. . '</em>'
  530. );
  531. $message->addParam($executed_queries);
  532. if ($import_notice) {
  533. $message->addString($import_notice);
  534. }
  535. if (isset($local_import_file)) {
  536. $message->addString('(' . htmlspecialchars($local_import_file) . ')');
  537. } else {
  538. $message->addString(
  539. '(' . htmlspecialchars($_FILES['import_file']['name']) . ')'
  540. );
  541. }
  542. }
  543. }
  544. // Did we hit timeout? Tell it user.
  545. if ($timeout_passed) {
  546. $message = PMA_Message::error(
  547. __('Script timeout passed, if you want to finish import, please resubmit same file and import will resume.')
  548. );
  549. if ($offset == 0 || (isset($original_skip) && $original_skip == $offset)) {
  550. $message->addString(
  551. __('However on last run no data has been parsed, this usually means phpMyAdmin won\'t be able to finish this import unless you increase php time limits.')
  552. );
  553. }
  554. }
  555. // if there is any message, copy it into $_SESSION as well,
  556. // so we can obtain it by AJAX call
  557. if (isset($message)) {
  558. $_SESSION['Import_message']['message'] = $message->getDisplay();
  559. }
  560. // Parse and analyze the query, for correct db and table name
  561. // in case of a query typed in the query window
  562. // (but if the query is too large, in case of an imported file, the parser
  563. // can choke on it so avoid parsing)
  564. if (strlen($sql_query) <= $GLOBALS['cfg']['MaxCharactersInDisplayedSQL']) {
  565. include_once 'libraries/parse_analyze.inc.php';
  566. }
  567. // There was an error?
  568. if (isset($my_die)) {
  569. foreach ($my_die as $key => $die) {
  570. PMA_Util::mysqlDie(
  571. $die['error'], $die['sql'], false, $err_url, $error
  572. );
  573. }
  574. }
  575. if ($go_sql) {
  576. // parse sql query
  577. include_once 'libraries/parse_analyze.inc.php';
  578. if (isset($ajax_reload) && $ajax_reload['reload'] === true) {
  579. $response = PMA_Response::getInstance();
  580. $response->addJSON('ajax_reload', $ajax_reload);
  581. }
  582. PMA_executeQueryAndSendQueryResponse(
  583. $analyzed_sql_results, false, $db, $table, null, $import_text, null,
  584. $analyzed_sql_results['is_affected'], null,
  585. null, null, null, $goto, $pmaThemeImage, null, null, null, $sql_query,
  586. null, null
  587. );
  588. } else if ($result) {
  589. // Save a Bookmark with more than one queries (if Bookmark label given).
  590. if (! empty($_POST['bkm_label']) && ! empty($import_text)) {
  591. PMA_storeTheQueryAsBookmark(
  592. $db, $GLOBALS['cfg']['Bookmark']['user'],
  593. $import_text, $_POST['bkm_label'],
  594. isset($_POST['bkm_replace']) ? $_POST['bkm_replace'] : null
  595. );
  596. }
  597. $response = PMA_Response::getInstance();
  598. $response->isSuccess(true);
  599. $response->addJSON('message', PMA_Message::success($msg));
  600. $response->addJSON(
  601. 'sql_query',
  602. PMA_Util::getMessage($msg, $sql_query, 'success')
  603. );
  604. } else if ($result == false) {
  605. $response = PMA_Response::getInstance();
  606. $response->isSuccess(false);
  607. $response->addJSON('message', PMA_Message::error($msg));
  608. } else {
  609. $active_page = $goto;
  610. include '' . $goto;
  611. }
  612. ?>