Merge pull request #431 from xmujay/0609_monitor
[phpmyadmin/aamir.git] / db_create.php
blobd9cea0ebb0efcd200dcfb973f81daa1ca55f3a14
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';
13 require_once 'libraries/mysql_charsets.inc.php';
14 if (! PMA_DRIZZLE) {
15 include_once 'libraries/replication.inc.php';
17 require 'libraries/build_html_for_db.lib.php';
19 /**
20 * Defines the url to return to in case of error in a sql statement
22 $err_url = 'index.php?' . PMA_generate_common_url();
24 /**
25 * Builds and executes the db creation sql query
27 $sql_query = 'CREATE DATABASE ' . PMA_Util::backquote($_POST['new_db']);
28 if (! empty($_POST['db_collation'])) {
29 list($db_charset) = explode('_', $_POST['db_collation']);
30 if (in_array($db_charset, $mysql_charsets)
31 && in_array($_POST['db_collation'], $mysql_collations[$db_charset])
32 ) {
33 $sql_query .= ' DEFAULT'
34 . PMA_generateCharsetQueryPart($_POST['db_collation']);
36 $db_collation_for_ajax = $_POST['db_collation'];
37 unset($db_charset);
39 $sql_query .= ';';
41 $result = $GLOBALS['dbi']->tryQuery($sql_query);
43 if (! $result) {
44 $message = PMA_Message::rawError($GLOBALS['dbi']->getError());
45 // avoid displaying the not-created db name in header or navi panel
46 $GLOBALS['db'] = '';
47 $GLOBALS['table'] = '';
49 /**
50 * If in an Ajax request, just display the message with {@link PMA_Response}
52 if ($GLOBALS['is_ajax_request'] == true) {
53 $response = PMA_Response::getInstance();
54 $response->isSuccess(false);
55 $response->addJSON('message', $message);
56 } else {
57 include_once 'index.php';
59 } else {
60 $message = PMA_Message::success(__('Database %1$s has been created.'));
61 $message->addParam($_POST['new_db']);
62 $GLOBALS['db'] = $_POST['new_db'];
64 /**
65 * If in an Ajax request, build the output and send it
67 if ($GLOBALS['is_ajax_request'] == true) {
68 //Construct the html for the new database, so that it can be appended to
69 // the list of databases on server_databases.php
71 /**
72 * Build the array to be passed to {@link PMA_generate_common_url}
73 * to generate the links
75 * @global array $GLOBALS['db_url_params']
76 * @name $db_url_params
78 $db_url_params['db'] = $_POST['new_db'];
80 $is_superuser = $GLOBALS['dbi']->isSuperuser();
81 $column_order = PMA_getColumnOrder();
82 $url_query = PMA_generate_common_url($_POST['new_db']);
84 /**
85 * String that will contain the output HTML
86 * @name $new_db_string
88 $new_db_string = '<tr>';
90 if (empty($db_collation_for_ajax)) {
91 $db_collation_for_ajax = PMA_getServerCollation();
94 // $dbstats comes from the create table dialog
95 if (! empty($dbstats)) {
96 $current = array(
97 'SCHEMA_NAME' => $_POST['new_db'],
98 'DEFAULT_COLLATION_NAME' => $db_collation_for_ajax,
99 'SCHEMA_TABLES' => '0',
100 'SCHEMA_TABLE_ROWS' => '0',
101 'SCHEMA_DATA_LENGTH' => '0',
102 'SCHEMA_MAX_DATA_LENGTH' => '0',
103 'SCHEMA_INDEX_LENGTH' => '0',
104 'SCHEMA_LENGTH' => '0',
105 'SCHEMA_DATA_FREE' => '0'
107 } else {
108 $current = array(
109 'SCHEMA_NAME' => $_POST['new_db']
113 list($column_order, $generated_html) = PMA_buildHtmlForDb(
114 $current, $is_superuser, $url_query,
115 $column_order, $replication_types, $replication_info
117 $new_db_string .= $generated_html;
119 $new_db_string .= '</tr>';
121 $response = PMA_Response::getInstance();
122 $response->addJSON('message', $message);
123 $response->addJSON('new_db_string', $new_db_string);
124 $response->addJSON(
125 'sql_query',
126 PMA_Util::getMessage(
127 null, $sql_query, 'success'
130 } else {
131 include_once '' . $cfg['DefaultTabDatabase'];