Merge branch 'QA_3_4'
[phpmyadmin.git] / db_create.php
blob3548f8fc00f6b6a7222cea6a638ffd1038faebd6
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';
13 $GLOBALS['js_include'][] = 'jquery/jquery-ui-1.8.custom.js';
15 require_once './libraries/mysql_charsets.lib.php';
16 if (!PMA_DRIZZLE) {
17 include './libraries/replication.inc.php';
19 require './libraries/build_html_for_db.lib.php';
21 PMA_checkParameters(array('new_db'));
23 /**
24 * Defines the url to return to in case of error in a sql statement
26 $err_url = 'main.php?' . PMA_generate_common_url();
28 /**
29 * Builds and executes the db creation sql query
31 $sql_query = 'CREATE DATABASE ' . PMA_backquote($new_db);
32 if (!empty($db_collation)) {
33 list($db_charset) = explode('_', $db_collation);
34 if (in_array($db_charset, $mysql_charsets) && in_array($db_collation, $mysql_collations[$db_charset])) {
35 $sql_query .= ' DEFAULT' . PMA_generateCharsetQueryPart($db_collation);
37 $db_collation_for_ajax = $db_collation;
38 unset($db_charset, $db_collation);
40 $sql_query .= ';';
42 $result = PMA_DBI_try_query($sql_query);
44 if (! $result) {
45 $message = PMA_Message::rawError(PMA_DBI_getError());
46 // avoid displaying the not-created db name in header or navi panel
47 $GLOBALS['db'] = '';
48 $GLOBALS['table'] = '';
50 /**
51 * If in an Ajax request, just display the message with {@link PMA_ajaxResponse}
53 if ($GLOBALS['is_ajax_request'] == true) {
54 PMA_ajaxResponse($message, false);
57 include_once './libraries/header.inc.php';
58 include_once './main.php';
59 } else {
60 $message = PMA_Message::success(__('Database %1$s has been created.'));
61 $message->addParam($new_db);
62 $GLOBALS['db'] = $new_db;
64 /**
65 * If in an Ajax request, build the output and send it
67 if ($GLOBALS['is_ajax_request'] == true) {
69 /**
70 * String containing the SQL Query formatted in pretty HTML
71 * @global array $GLOBALS['extra_data']
72 * @name $extra_data
74 $extra_data['sql_query'] = PMA_showMessage(null, $sql_query, 'success');
76 //Construct the html for the new database, so that it can be appended to the list of databases on server_databases.php
78 /**
79 * Build the array to be passed to {@link PMA_generate_common_url} to generate the links
80 * @global array $GLOBALS['db_url_params']
81 * @name $db_url_params
83 $db_url_params['db'] = $new_db;
85 $is_superuser = PMA_isSuperuser();
86 $column_order = PMA_getColumnOrder();
87 $url_query = PMA_generate_common_url($new_db);
89 /**
90 * String that will contain the output HTML
91 * @name $new_db_string
93 $new_db_string = '<tr>';
95 if (empty($db_collation_for_ajax)) {
96 $db_collation_for_ajax = PMA_getServerCollation();
99 // $dbstats comes from the create table dialog
100 if (! empty($dbstats)) {
101 $current = array(
102 'SCHEMA_NAME' => $new_db,
103 'DEFAULT_COLLATION_NAME' => $db_collation_for_ajax,
104 'SCHEMA_TABLES' => '0',
105 'SCHEMA_TABLE_ROWS' => '0',
106 'SCHEMA_DATA_LENGTH' => '0',
107 'SCHEMA_MAX_DATA_LENGTH' => '0',
108 'SCHEMA_INDEX_LENGTH' => '0',
109 'SCHEMA_LENGTH' => '0',
110 'SCHEMA_DATA_FREE' => '0'
112 } else {
113 $current = array(
114 'SCHEMA_NAME' => $new_db
118 list($column_order, $generated_html) = PMA_buildHtmlForDb($current, $is_superuser, (isset($checkall) ? $checkall : ''), $url_query, $column_order, $replication_types, $replication_info);
119 $new_db_string .= $generated_html;
121 $new_db_string .= '</tr>';
123 $extra_data['new_db_string'] = $new_db_string;
125 PMA_ajaxResponse($message, true, $extra_data);
128 include_once './libraries/header.inc.php';
129 include_once './' . $cfg['DefaultTabDatabase'];