2 /* vim: set expandtab sw=4 ts=4 sts=4: */
9 * Gets some core libraries
11 require_once 'libraries/common.inc.php';
13 require_once 'libraries/mysql_charsets.lib.php';
15 include_once 'libraries/replication.inc.php';
17 require 'libraries/build_html_for_db.lib.php';
20 * Sets globals from $_POST
26 foreach ($post_params as $one_post_param) {
27 if (isset($_POST[$one_post_param])) {
28 $GLOBALS[$one_post_param] = $_POST[$one_post_param];
32 PMA_Util
::checkParameters(array('new_db'));
35 * Defines the url to return to in case of error in a sql statement
37 $err_url = 'index.php?' . PMA_generate_common_url();
40 * Builds and executes the db creation sql query
42 $sql_query = 'CREATE DATABASE ' . PMA_Util
::backquote($new_db);
43 if (! empty($db_collation)) {
44 list($db_charset) = explode('_', $db_collation);
45 if (in_array($db_charset, $mysql_charsets)
46 && in_array($db_collation, $mysql_collations[$db_charset])
48 $sql_query .= ' DEFAULT' . PMA_generateCharsetQueryPart($db_collation);
50 $db_collation_for_ajax = $db_collation;
51 unset($db_charset, $db_collation);
55 $result = PMA_DBI_try_query($sql_query);
58 $message = PMA_Message
::rawError(PMA_DBI_getError());
59 // avoid displaying the not-created db name in header or navi panel
61 $GLOBALS['table'] = '';
64 * If in an Ajax request, just display the message with {@link PMA_Response}
66 if ($GLOBALS['is_ajax_request'] == true) {
67 $response = PMA_Response
::getInstance();
68 $response->isSuccess(false);
69 $response->addJSON('message', $message);
71 include_once 'index.php';
74 $message = PMA_Message
::success(__('Database %1$s has been created.'));
75 $message->addParam($new_db);
76 $GLOBALS['db'] = $new_db;
79 * If in an Ajax request, build the output and send it
81 if ($GLOBALS['is_ajax_request'] == true) {
82 //Construct the html for the new database, so that it can be appended to
83 // the list of databases on server_databases.php
86 * Build the array to be passed to {@link PMA_generate_common_url}
87 * to generate the links
89 * @global array $GLOBALS['db_url_params']
90 * @name $db_url_params
92 $db_url_params['db'] = $new_db;
94 $is_superuser = PMA_isSuperuser();
95 $column_order = PMA_getColumnOrder();
96 $url_query = PMA_generate_common_url($new_db);
99 * String that will contain the output HTML
100 * @name $new_db_string
102 $new_db_string = '<tr>';
104 if (empty($db_collation_for_ajax)) {
105 $db_collation_for_ajax = PMA_getServerCollation();
108 // $dbstats comes from the create table dialog
109 if (! empty($dbstats)) {
111 'SCHEMA_NAME' => $new_db,
112 'DEFAULT_COLLATION_NAME' => $db_collation_for_ajax,
113 'SCHEMA_TABLES' => '0',
114 'SCHEMA_TABLE_ROWS' => '0',
115 'SCHEMA_DATA_LENGTH' => '0',
116 'SCHEMA_MAX_DATA_LENGTH' => '0',
117 'SCHEMA_INDEX_LENGTH' => '0',
118 'SCHEMA_LENGTH' => '0',
119 'SCHEMA_DATA_FREE' => '0'
123 'SCHEMA_NAME' => $new_db
127 list($column_order, $generated_html) = PMA_buildHtmlForDb(
128 $current, $is_superuser, $url_query,
129 $column_order, $replication_types, $replication_info
131 $new_db_string .= $generated_html;
133 $new_db_string .= '</tr>';
135 $response = PMA_Response
::getInstance();
136 $response->addJSON('message', $message);
137 $response->addJSON('new_db_string', $new_db_string);
140 PMA_Util
::getMessage(
141 null, $sql_query, 'success'
145 include_once '' . $cfg['DefaultTabDatabase'];