Fixed descriptions of geometry types - these are column types, not OpenGIS objects
[phpmyadmin.git] / db_create.php
blobd3e50624148ff343e88ee7a6a4f4bd15b5c7868d
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 /**
5 * @package PhpMyAdmin
6 */
8 /**
9 * Gets some core libraries
11 require_once 'libraries/common.inc.php';
12 $GLOBALS['js_include'][] = 'functions.js';
14 require_once 'libraries/mysql_charsets.lib.php';
15 if (! PMA_DRIZZLE) {
16 include_once 'libraries/replication.inc.php';
18 require 'libraries/build_html_for_db.lib.php';
20 /**
21 * Sets globals from $_POST
23 $post_params = array(
24 'db_collation',
25 'new_db'
27 foreach ($post_params as $one_post_param) {
28 if (isset($_POST[$one_post_param])) {
29 $GLOBALS[$one_post_param] = $_POST[$one_post_param];
33 PMA_checkParameters(array('new_db'));
35 /**
36 * Defines the url to return to in case of error in a sql statement
38 $err_url = 'main.php?' . PMA_generate_common_url();
40 /**
41 * Builds and executes the db creation sql query
43 $sql_query = 'CREATE DATABASE ' . PMA_backquote($new_db);
44 if (! empty($db_collation)) {
45 list($db_charset) = explode('_', $db_collation);
46 if (in_array($db_charset, $mysql_charsets)
47 && in_array($db_collation, $mysql_collations[$db_charset])
48 ) {
49 $sql_query .= ' DEFAULT' . PMA_generateCharsetQueryPart($db_collation);
51 $db_collation_for_ajax = $db_collation;
52 unset($db_charset, $db_collation);
54 $sql_query .= ';';
56 $result = PMA_DBI_try_query($sql_query);
58 if (! $result) {
59 $message = PMA_Message::rawError(PMA_DBI_getError());
60 // avoid displaying the not-created db name in header or navi panel
61 $GLOBALS['db'] = '';
62 $GLOBALS['table'] = '';
64 /**
65 * If in an Ajax request, just display the message with {@link PMA_ajaxResponse}
67 if ($GLOBALS['is_ajax_request'] == true) {
68 PMA_ajaxResponse($message, false);
71 include_once 'libraries/header.inc.php';
72 include_once 'main.php';
73 } else {
74 $message = PMA_Message::success(__('Database %1$s has been created.'));
75 $message->addParam($new_db);
76 $GLOBALS['db'] = $new_db;
78 /**
79 * If in an Ajax request, build the output and send it
81 if ($GLOBALS['is_ajax_request'] == true) {
83 /**
84 * String containing the SQL Query formatted in pretty HTML
85 * @global array $GLOBALS['extra_data']
86 * @name $extra_data
88 $extra_data['sql_query'] = PMA_showMessage(null, $sql_query, 'success');
90 //Construct the html for the new database, so that it can be appended to
91 // the list of databases on server_databases.php
93 /**
94 * Build the array to be passed to {@link PMA_generate_common_url}
95 * to generate the links
97 * @global array $GLOBALS['db_url_params']
98 * @name $db_url_params
100 $db_url_params['db'] = $new_db;
102 $is_superuser = PMA_isSuperuser();
103 $column_order = PMA_getColumnOrder();
104 $url_query = PMA_generate_common_url($new_db);
107 * String that will contain the output HTML
108 * @name $new_db_string
110 $new_db_string = '<tr>';
112 if (empty($db_collation_for_ajax)) {
113 $db_collation_for_ajax = PMA_getServerCollation();
116 // $dbstats comes from the create table dialog
117 if (! empty($dbstats)) {
118 $current = array(
119 'SCHEMA_NAME' => $new_db,
120 'DEFAULT_COLLATION_NAME' => $db_collation_for_ajax,
121 'SCHEMA_TABLES' => '0',
122 'SCHEMA_TABLE_ROWS' => '0',
123 'SCHEMA_DATA_LENGTH' => '0',
124 'SCHEMA_MAX_DATA_LENGTH' => '0',
125 'SCHEMA_INDEX_LENGTH' => '0',
126 'SCHEMA_LENGTH' => '0',
127 'SCHEMA_DATA_FREE' => '0'
129 } else {
130 $current = array(
131 'SCHEMA_NAME' => $new_db
135 list($column_order, $generated_html) = PMA_buildHtmlForDb(
136 $current, $is_superuser, (isset($checkall) ? $checkall : ''),
137 $url_query, $column_order, $replication_types, $replication_info
139 $new_db_string .= $generated_html;
141 $new_db_string .= '</tr>';
143 $extra_data['new_db_string'] = $new_db_string;
145 PMA_ajaxResponse($message, true, $extra_data);
148 include_once 'libraries/header.inc.php';
149 include_once '' . $cfg['DefaultTabDatabase'];