SqlController.php 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. <?php
  2. declare(strict_types=1);
  3. namespace PhpMyAdmin\Controllers\Server;
  4. use PhpMyAdmin\Config\PageSettings;
  5. use PhpMyAdmin\Controllers\AbstractController;
  6. use PhpMyAdmin\DatabaseInterface;
  7. use PhpMyAdmin\Response;
  8. use PhpMyAdmin\SqlQueryForm;
  9. use PhpMyAdmin\Template;
  10. use PhpMyAdmin\Url;
  11. /**
  12. * Server SQL executor
  13. */
  14. class SqlController extends AbstractController
  15. {
  16. /** @var SqlQueryForm */
  17. private $sqlQueryForm;
  18. /** @var DatabaseInterface */
  19. private $dbi;
  20. /**
  21. * @param Response $response
  22. * @param DatabaseInterface $dbi
  23. */
  24. public function __construct($response, Template $template, SqlQueryForm $sqlQueryForm, $dbi)
  25. {
  26. parent::__construct($response, $template);
  27. $this->sqlQueryForm = $sqlQueryForm;
  28. $this->dbi = $dbi;
  29. }
  30. public function index(): void
  31. {
  32. global $err_url;
  33. $this->addScriptFiles([
  34. 'makegrid.js',
  35. 'vendor/jquery/jquery.uitablefilter.js',
  36. 'vendor/stickyfill.min.js',
  37. 'sql.js',
  38. ]);
  39. $pageSettings = new PageSettings('Sql');
  40. $this->response->addHTML($pageSettings->getErrorHTML());
  41. $this->response->addHTML($pageSettings->getHTML());
  42. $err_url = Url::getFromRoute('/');
  43. if ($this->dbi->isSuperUser()) {
  44. $this->dbi->selectDb('mysql');
  45. }
  46. $this->response->addHTML($this->sqlQueryForm->getHtml());
  47. }
  48. }