Removing old documentation
[openemr.git] / phpmyadmin / db_create.php
blob76e9cb5737013dbfcb07d13491121ee861689f50
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 /**
4 * Database creating page
6 * @package PhpMyAdmin
7 */
9 /**
10 * Gets some core libraries
12 require_once 'libraries/common.inc.php';
14 require_once 'libraries/mysql_charsets.inc.php';
15 if (! PMA_DRIZZLE) {
16 include_once 'libraries/replication.inc.php';
18 require 'libraries/build_html_for_db.lib.php';
20 if (! isset($_POST['new_db'])) {
21 PMA_Util::checkParameters(array('new_db'));
24 /**
25 * Defines the url to return to in case of error in a sql statement
27 $err_url = 'index.php' . PMA_URL_getCommon();
29 /**
30 * Builds and executes the db creation sql query
32 $sql_query = 'CREATE DATABASE ' . PMA_Util::backquote($_POST['new_db']);
33 if (! empty($_POST['db_collation'])) {
34 list($db_charset) = explode('_', $_POST['db_collation']);
35 if (in_array($db_charset, $mysql_charsets)
36 && in_array($_POST['db_collation'], $mysql_collations[$db_charset])
37 ) {
38 $sql_query .= ' DEFAULT'
39 . PMA_generateCharsetQueryPart($_POST['db_collation']);
41 $db_collation_for_ajax = $_POST['db_collation'];
42 unset($db_charset);
44 $sql_query .= ';';
46 $result = $GLOBALS['dbi']->tryQuery($sql_query);
48 if (! $result) {
49 $message = PMA_Message::rawError($GLOBALS['dbi']->getError());
50 // avoid displaying the not-created db name in header or navi panel
51 $GLOBALS['db'] = '';
52 $GLOBALS['table'] = '';
54 /**
55 * If in an Ajax request, just display the message with {@link PMA_Response}
57 if ($GLOBALS['is_ajax_request'] == true) {
58 $response = PMA_Response::getInstance();
59 $response->isSuccess(false);
60 $response->addJSON('message', $message);
61 } else {
62 include_once 'index.php';
64 } else {
65 $message = PMA_Message::success(__('Database %1$s has been created.'));
66 $message->addParam($_POST['new_db']);
67 $GLOBALS['db'] = $_POST['new_db'];
69 /**
70 * If in an Ajax request, build the output and send it
72 if ($GLOBALS['is_ajax_request'] == true) {
73 //Construct the html for the new database, so that it can be appended to
74 // the list of databases on server_databases.php
76 /**
77 * Build the array to be passed to {@link PMA_URL_getCommon}
78 * to generate the links
80 * @global array $GLOBALS['db_url_params']
81 * @name $db_url_params
83 $db_url_params['db'] = $_POST['new_db'];
85 $is_superuser = $GLOBALS['dbi']->isSuperuser();
86 $column_order = PMA_getColumnOrder();
87 $url_query = PMA_URL_getCommon(array('db' => $_POST['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' => $_POST['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' => $_POST['new_db'],
115 'DEFAULT_COLLATION_NAME' => $db_collation_for_ajax
119 list($column_order, $generated_html) = PMA_buildHtmlForDb(
120 $current, $is_superuser, $url_query,
121 $column_order, $replication_types, $GLOBALS['replication_info']
123 $new_db_string .= $generated_html;
125 $new_db_string .= '</tr>';
127 $response = PMA_Response::getInstance();
128 $response->addJSON('message', $message);
129 $response->addJSON('new_db_string', $new_db_string);
130 $response->addJSON(
131 'sql_query',
132 PMA_Util::getMessage(
133 null, $sql_query, 'success'
136 $response->addJSON(
137 'url_query',
138 PMA_Util::getScriptNameForOption(
139 $GLOBALS['cfg']['DefaultTabDatabase'], 'database'
141 . $url_query . '&amp;db='
142 . urlencode($current['SCHEMA_NAME'])
144 } else {
145 include_once '' . PMA_Util::getScriptNameForOption(
146 $GLOBALS['cfg']['DefaultTabDatabase'], 'database'