db_common.inc.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. <?php
  2. /* vim: set expandtab sw=4 ts=4 sts=4: */
  3. /**
  4. * Common includes for the database level views
  5. *
  6. * @package PhpMyAdmin
  7. */
  8. if (! defined('PHPMYADMIN')) {
  9. exit;
  10. }
  11. /**
  12. * Gets some core libraries
  13. */
  14. require_once './libraries/bookmark.lib.php';
  15. PMA_Util::checkParameters(array('db'));
  16. $is_show_stats = $cfg['ShowStats'];
  17. $db_is_system_schema = $GLOBALS['dbi']->isSystemSchema($db);
  18. if ($db_is_system_schema) {
  19. $is_show_stats = false;
  20. }
  21. /**
  22. * Defines the urls to return to in case of error in a sql statement
  23. */
  24. $err_url_0 = 'index.php?' . PMA_URL_getCommon();
  25. $err_url = $cfg['DefaultTabDatabase'] . '?' . PMA_URL_getCommon($db);
  26. /**
  27. * Ensures the database exists (else move to the "parent" script) and displays
  28. * headers
  29. */
  30. if (! isset($is_db) || ! $is_db) {
  31. if (strlen($db)) {
  32. $is_db = $GLOBALS['dbi']->selectDb($db);
  33. // This "Command out of sync" 2014 error may happen, for example
  34. // after calling a MySQL procedure; at this point we can't select
  35. // the db but it's not necessarily wrong
  36. if ($GLOBALS['dbi']->getError() && $GLOBALS['errno'] == 2014) {
  37. $is_db = true;
  38. unset($GLOBALS['errno']);
  39. }
  40. }
  41. // Not a valid db name -> back to the welcome page
  42. $uri = $cfg['PmaAbsoluteUri'] . 'index.php?'
  43. . PMA_URL_getCommon('', '', '&')
  44. . (isset($message) ? '&message=' . urlencode($message) : '') . '&reload=1';
  45. if (! strlen($db) || ! $is_db) {
  46. $response = PMA_Response::getInstance();
  47. if ($response->isAjax()) {
  48. $response->isSuccess(false);
  49. $response->addJSON(
  50. 'message',
  51. PMA_Message::error(__('No databases selected.'))
  52. );
  53. } else {
  54. PMA_sendHeaderLocation($uri);
  55. }
  56. exit;
  57. }
  58. } // end if (ensures db exists)
  59. /**
  60. * Changes database charset if requested by the user
  61. */
  62. if (isset($_REQUEST['submitcollation'])
  63. && isset($_REQUEST['db_collation'])
  64. && ! empty($_REQUEST['db_collation'])
  65. ) {
  66. list($db_charset) = explode('_', $_REQUEST['db_collation']);
  67. $sql_query = 'ALTER DATABASE '
  68. . PMA_Util::backquote($db)
  69. . ' DEFAULT' . PMA_generateCharsetQueryPart($_REQUEST['db_collation']);
  70. $result = $GLOBALS['dbi']->query($sql_query);
  71. $message = PMA_Message::success();
  72. unset($db_charset);
  73. /**
  74. * If we are in an Ajax request, let us stop the execution here. Necessary for
  75. * db charset change action on db_operations.php. If this causes a bug on
  76. * other pages, we might have to move this to a different location.
  77. */
  78. if ( $GLOBALS['is_ajax_request'] == true) {
  79. $response = PMA_Response::getInstance();
  80. $response->isSuccess($message->isSuccess());
  81. $response->addJSON('message', $message);
  82. exit;
  83. }
  84. }
  85. /**
  86. * Set parameters for links
  87. */
  88. $url_query = PMA_URL_getCommon($db);
  89. ?>