2 /* vim: set expandtab sw=4 ts=4 sts=4: */
4 * Common includes for the database level views
8 if (! defined('PHPMYADMIN')) {
13 * Gets some core libraries
15 require_once './libraries/bookmark.lib.php';
17 PMA_Util
::checkParameters(array('db'));
22 $is_show_stats = $cfg['ShowStats'];
24 $db_is_system_schema = $GLOBALS['dbi']->isSystemSchema($db);
25 if ($db_is_system_schema) {
26 $is_show_stats = false;
30 * Defines the urls to return to in case of error in a sql statement
32 $err_url_0 = 'index.php' . PMA_URL_getCommon();
34 $err_url = PMA_Util
::getScriptNameForOption(
35 $GLOBALS['cfg']['DefaultTabDatabase'], 'database'
37 . PMA_URL_getCommon(array('db' => $db));
39 /** @var PMA_String $pmaString */
40 $pmaString = $GLOBALS['PMA_String'];
43 * Ensures the database exists (else move to the "parent" script) and displays
46 if (! isset($is_db) ||
! $is_db) {
47 if (/*overload*/mb_strlen($db)) {
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 $uri = $cfg['PmaAbsoluteUri'] . 'index.php'
61 . PMA_URL_getCommon(array(), 'text')
62 . (isset($message) ?
'&message=' . urlencode($message) : '') . '&reload=1';
63 if (!/*overload*/mb_strlen($db) ||
! $is_db) {
64 $response = PMA_Response
::getInstance();
65 if ($response->isAjax()) {
66 $response->isSuccess(false);
69 PMA_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_Util
::backquote($db)
88 . ' DEFAULT' . PMA_generateCharsetQueryPart($_REQUEST['db_collation']);
89 $result = $GLOBALS['dbi']->query($sql_query);
90 $message = PMA_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 ($GLOBALS['is_ajax_request'] == true) {
99 $response = PMA_Response
::getInstance();
100 $response->isSuccess($message->isSuccess());
101 $response->addJSON('message', $message);
107 * Set parameters for links
109 $url_query = PMA_URL_getCommon(array('db' => $db));