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