SqlController.php 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. <?php
  2. declare(strict_types=1);
  3. namespace PhpMyAdmin\Controllers\Database;
  4. use PhpMyAdmin\Config\PageSettings;
  5. use PhpMyAdmin\Response;
  6. use PhpMyAdmin\SqlQueryForm;
  7. use PhpMyAdmin\Template;
  8. use PhpMyAdmin\Url;
  9. use PhpMyAdmin\Util;
  10. use function htmlspecialchars;
  11. /**
  12. * Database SQL executor
  13. */
  14. class SqlController extends AbstractController
  15. {
  16. /** @var SqlQueryForm */
  17. private $sqlQueryForm;
  18. /**
  19. * @param Response $response
  20. * @param string $db Database name
  21. */
  22. public function __construct($response, Template $template, $db, SqlQueryForm $sqlQueryForm)
  23. {
  24. parent::__construct($response, $template, $db);
  25. $this->sqlQueryForm = $sqlQueryForm;
  26. }
  27. public function index(): void
  28. {
  29. global $goto, $back, $db, $cfg, $err_url;
  30. $this->addScriptFiles([
  31. 'makegrid.js',
  32. 'vendor/jquery/jquery.uitablefilter.js',
  33. 'vendor/stickyfill.min.js',
  34. 'sql.js',
  35. ]);
  36. $pageSettings = new PageSettings('Sql');
  37. $this->response->addHTML($pageSettings->getErrorHTML());
  38. $this->response->addHTML($pageSettings->getHTML());
  39. Util::checkParameters(['db']);
  40. $err_url = Util::getScriptNameForOption($cfg['DefaultTabDatabase'], 'database');
  41. $err_url .= Url::getCommon(['db' => $db], '&');
  42. if (! $this->hasDatabase()) {
  43. return;
  44. }
  45. /**
  46. * After a syntax error, we return to this script
  47. * with the typed query in the textarea.
  48. */
  49. $goto = Url::getFromRoute('/database/sql');
  50. $back = $goto;
  51. $this->response->addHTML($this->sqlQueryForm->getHtml(
  52. true,
  53. false,
  54. isset($_POST['delimiter'])
  55. ? htmlspecialchars($_POST['delimiter'])
  56. : ';'
  57. ));
  58. }
  59. }