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
58 $params = array('reload' => '1');
59 if (isset($message)) {
60 $params['message'] = $message;
62 $uri = './index.php' . URL
::getCommonRaw($params);
63 if (strlen($db) === 0 ||
! $is_db) {
64 $response = Response
::getInstance();
65 if ($response->isAjax()) {
66 $response->setRequestStatus(false);
69 Message
::error(__('No databases selected.'))
72 PMA_sendHeaderLocation($uri);
76 } // end if (ensures db exists)
79 * Changes database charset if requested by the user
81 if (isset($_REQUEST['submitcollation'])
82 && isset($_REQUEST['db_collation'])
83 && ! empty($_REQUEST['db_collation'])
85 list($db_charset) = explode('_', $_REQUEST['db_collation']);
86 $sql_query = 'ALTER DATABASE '
87 . PMA\libraries\Util
::backquote($db)
88 . ' DEFAULT' . Util
::getCharsetQueryPart($_REQUEST['db_collation']);
89 $result = $GLOBALS['dbi']->query($sql_query);
90 $message = Message
::success();
94 * If we are in an Ajax request, let us stop the execution here. Necessary for
95 * db charset change action on db_operations.php. If this causes a bug on
96 * other pages, we might have to move this to a different location.
98 if ($response->isAjax()) {
99 $response->setRequestStatus($message->isSuccess());
100 $response->addJSON('message', $message);
106 * Set parameters for links
108 $url_query = URL
::getCommon(array('db' => $db));