public function createDatabaseAction()
{
/**
* Builds and executes the db creation sql query
*/
$sql_query = 'CREATE DATABASE ' . Util::backquote($_POST['new_db']);
if (!empty($_POST['db_collation'])) {
list($db_charset) = explode('_', $_POST['db_collation']);
$charsets = Charsets::getMySQLCharsets();
$collations = Charsets::getMySQLCollations();
if (in_array($db_charset, $charsets) && in_array($_POST['db_collation'], $collations[$db_charset])) {
$sql_query .= ' DEFAULT' . Util::getCharsetQueryPart($_POST['db_collation']);
}
}
$sql_query .= ';';
$result = $GLOBALS['dbi']->tryQuery($sql_query);
if (!$result) {
// avoid displaying the not-created db name in header or navi panel
$GLOBALS['db'] = '';
$message = Message::rawError($GLOBALS['dbi']->getError());
$this->response->setRequestStatus(false);
$this->response->addJSON('message', $message);
} else {
$GLOBALS['db'] = $_POST['new_db'];
$message = Message::success(__('Database %1$s has been created.'));
$message->addParam($_POST['new_db']);
$this->response->addJSON('message', $message);
$this->response->addJSON('sql_query', Util::getMessage(null, $sql_query, 'success'));
$url_query = URL::getCommon(array('db' => $_POST['new_db']));
$this->response->addJSON('url_query', Util::getScriptNameForOption($GLOBALS['cfg']['DefaultTabDatabase'], 'database') . $url_query . '&db=' . urlencode($_POST['new_db']));
}
}