db_create.php 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. <?php
  2. /* vim: set expandtab sw=4 ts=4 sts=4: */
  3. /**
  4. * Database creating page
  5. *
  6. * @package PhpMyAdmin
  7. */
  8. /**
  9. * Gets some core libraries
  10. */
  11. require_once 'libraries/common.inc.php';
  12. require_once 'libraries/mysql_charsets.inc.php';
  13. if (! PMA_DRIZZLE) {
  14. include_once 'libraries/replication.inc.php';
  15. }
  16. require 'libraries/build_html_for_db.lib.php';
  17. /**
  18. * Defines the url to return to in case of error in a sql statement
  19. */
  20. $err_url = 'index.php?' . PMA_URL_getCommon();
  21. /**
  22. * Builds and executes the db creation sql query
  23. */
  24. $sql_query = 'CREATE DATABASE ' . PMA_Util::backquote($_POST['new_db']);
  25. if (! empty($_POST['db_collation'])) {
  26. list($db_charset) = explode('_', $_POST['db_collation']);
  27. if (in_array($db_charset, $mysql_charsets)
  28. && in_array($_POST['db_collation'], $mysql_collations[$db_charset])
  29. ) {
  30. $sql_query .= ' DEFAULT'
  31. . PMA_generateCharsetQueryPart($_POST['db_collation']);
  32. }
  33. $db_collation_for_ajax = $_POST['db_collation'];
  34. unset($db_charset);
  35. }
  36. $sql_query .= ';';
  37. $result = $GLOBALS['dbi']->tryQuery($sql_query);
  38. if (! $result) {
  39. $message = PMA_Message::rawError($GLOBALS['dbi']->getError());
  40. // avoid displaying the not-created db name in header or navi panel
  41. $GLOBALS['db'] = '';
  42. $GLOBALS['table'] = '';
  43. /**
  44. * If in an Ajax request, just display the message with {@link PMA_Response}
  45. */
  46. if ($GLOBALS['is_ajax_request'] == true) {
  47. $response = PMA_Response::getInstance();
  48. $response->isSuccess(false);
  49. $response->addJSON('message', $message);
  50. } else {
  51. include_once 'index.php';
  52. }
  53. } else {
  54. $message = PMA_Message::success(__('Database %1$s has been created.'));
  55. $message->addParam($_POST['new_db']);
  56. $GLOBALS['db'] = $_POST['new_db'];
  57. /**
  58. * If in an Ajax request, build the output and send it
  59. */
  60. if ($GLOBALS['is_ajax_request'] == true) {
  61. //Construct the html for the new database, so that it can be appended to
  62. // the list of databases on server_databases.php
  63. /**
  64. * Build the array to be passed to {@link PMA_URL_getCommon}
  65. * to generate the links
  66. *
  67. * @global array $GLOBALS['db_url_params']
  68. * @name $db_url_params
  69. */
  70. $db_url_params['db'] = $_POST['new_db'];
  71. $is_superuser = $GLOBALS['dbi']->isSuperuser();
  72. $column_order = PMA_getColumnOrder();
  73. $url_query = PMA_URL_getCommon($_POST['new_db']);
  74. /**
  75. * String that will contain the output HTML
  76. * @name $new_db_string
  77. */
  78. $new_db_string = '<tr>';
  79. if (empty($db_collation_for_ajax)) {
  80. $db_collation_for_ajax = PMA_getServerCollation();
  81. }
  82. // $dbstats comes from the create table dialog
  83. if (! empty($dbstats)) {
  84. $current = array(
  85. 'SCHEMA_NAME' => $_POST['new_db'],
  86. 'DEFAULT_COLLATION_NAME' => $db_collation_for_ajax,
  87. 'SCHEMA_TABLES' => '0',
  88. 'SCHEMA_TABLE_ROWS' => '0',
  89. 'SCHEMA_DATA_LENGTH' => '0',
  90. 'SCHEMA_MAX_DATA_LENGTH' => '0',
  91. 'SCHEMA_INDEX_LENGTH' => '0',
  92. 'SCHEMA_LENGTH' => '0',
  93. 'SCHEMA_DATA_FREE' => '0'
  94. );
  95. } else {
  96. $current = array(
  97. 'SCHEMA_NAME' => $_POST['new_db'],
  98. 'DEFAULT_COLLATION_NAME' => $db_collation_for_ajax
  99. );
  100. }
  101. list($column_order, $generated_html) = PMA_buildHtmlForDb(
  102. $current, $is_superuser, $url_query,
  103. $column_order, $replication_types, $replication_info
  104. );
  105. $new_db_string .= $generated_html;
  106. $new_db_string .= '</tr>';
  107. $response = PMA_Response::getInstance();
  108. $response->addJSON('message', $message);
  109. $response->addJSON('new_db_string', $new_db_string);
  110. $response->addJSON(
  111. 'sql_query',
  112. PMA_Util::getMessage(
  113. null, $sql_query, 'success'
  114. )
  115. );
  116. } else {
  117. include_once '' . $cfg['DefaultTabDatabase'];
  118. }
  119. }
  120. ?>