2 /* vim: set expandtab sw=4 ts=4 sts=4: */
4 * Common includes for the database level views
8 use PMA\libraries\Message
;
9 use PMA\libraries\Response
;
10 use PMA\libraries\URL
;
11 use PMA\libraries\Util
;
13 if (! defined('PHPMYADMIN')) {
17 PMA\libraries\Util
::checkParameters(array('db'));
22 $response = Response
::getInstance();
23 $is_show_stats = $cfg['ShowStats'];
25 $db_is_system_schema = $GLOBALS['dbi']->isSystemSchema($db);
26 if ($db_is_system_schema) {
27 $is_show_stats = false;
31 * Defines the urls to return to in case of error in a sql statement
33 $err_url_0 = 'index.php' . URL
::getCommon();
35 $err_url = PMA\libraries\Util
::getScriptNameForOption(
36 $GLOBALS['cfg']['DefaultTabDatabase'], 'database'
38 . URL
::getCommon(array('db' => $db));
41 * Ensures the database exists (else move to the "parent" script) and displays
44 if (! isset($is_db) ||
! $is_db) {
45 if (strlen($db) > 0) {
46 $is_db = $GLOBALS['dbi']->selectDb($db);
47 // This "Command out of sync" 2014 error may happen, for example
48 // after calling a MySQL procedure; at this point we can't select
49 // the db but it's not necessarily wrong
50 if ($GLOBALS['dbi']->getError() && $GLOBALS['errno'] == 2014) {
52 unset($GLOBALS['errno']);
57 // Not a valid db name -> back to the welcome page
59 . URL
::getCommonRaw(array())
60 . (isset($message) ?
'&message=' . urlencode($message) : '') . '&reload=1';
61 if (strlen($db) === 0 ||
! $is_db) {
62 $response = Response
::getInstance();
63 if ($response->isAjax()) {
64 $response->setRequestStatus(false);
67 Message
::error(__('No databases selected.'))
70 PMA_sendHeaderLocation($uri);
74 } // end if (ensures db exists)
77 * Changes database charset if requested by the user
79 if (isset($_REQUEST['submitcollation'])
80 && isset($_REQUEST['db_collation'])
81 && ! empty($_REQUEST['db_collation'])
83 list($db_charset) = explode('_', $_REQUEST['db_collation']);
84 $sql_query = 'ALTER DATABASE '
85 . PMA\libraries\Util
::backquote($db)
86 . ' DEFAULT' . Util
::getCharsetQueryPart($_REQUEST['db_collation']);
87 $result = $GLOBALS['dbi']->query($sql_query);
88 $message = Message
::success();
92 * If we are in an Ajax request, let us stop the execution here. Necessary for
93 * db charset change action on db_operations.php. If this causes a bug on
94 * other pages, we might have to move this to a different location.
96 if ($response->isAjax()) {
97 $response->setRequestStatus($message->isSuccess());
98 $response->addJSON('message', $message);
104 * Set parameters for links
106 $url_query = URL
::getCommon(array('db' => $db));