2 /* vim: set expandtab sw=4 ts=4 sts=4: */
4 * Common includes for the database level views
10 use PhpMyAdmin\Message
;
11 use PhpMyAdmin\Response
;
14 use PhpMyAdmin\Operations
;
16 if (! defined('PHPMYADMIN')) {
20 PhpMyAdmin\Util
::checkParameters(array('db'));
25 $response = Response
::getInstance();
26 $is_show_stats = $cfg['ShowStats'];
28 $db_is_system_schema = $GLOBALS['dbi']->isSystemSchema($db);
29 if ($db_is_system_schema) {
30 $is_show_stats = false;
34 * Defines the urls to return to in case of error in a sql statement
36 $err_url_0 = 'index.php' . Url
::getCommon();
38 $err_url = PhpMyAdmin\Util
::getScriptNameForOption(
39 $GLOBALS['cfg']['DefaultTabDatabase'], 'database'
41 . Url
::getCommon(array('db' => $db));
44 * Ensures the database exists (else move to the "parent" script) and displays
47 if (! isset($is_db) ||
! $is_db) {
48 if (strlen($db) > 0) {
49 $is_db = $GLOBALS['dbi']->selectDb($db);
50 // This "Command out of sync" 2014 error may happen, for example
51 // after calling a MySQL procedure; at this point we can't select
52 // the db but it's not necessarily wrong
53 if ($GLOBALS['dbi']->getError() && $GLOBALS['errno'] == 2014) {
55 unset($GLOBALS['errno']);
60 // Not a valid db name -> back to the welcome page
61 $params = array('reload' => '1');
62 if (isset($message)) {
63 $params['message'] = $message;
65 $uri = './index.php' . Url
::getCommonRaw($params);
66 if (strlen($db) === 0 ||
! $is_db) {
67 $response = Response
::getInstance();
68 if ($response->isAjax()) {
69 $response->setRequestStatus(false);
72 Message
::error(__('No databases selected.'))
75 Core
::sendHeaderLocation($uri);
79 } // end if (ensures db exists)
82 * Changes database charset if requested by the user
84 if (isset($_POST['submitcollation'])
85 && isset($_POST['db_collation'])
86 && ! empty($_POST['db_collation'])
88 list($db_charset) = explode('_', $_POST['db_collation']);
89 $sql_query = 'ALTER DATABASE '
90 . PhpMyAdmin\Util
::backquote($db)
91 . ' DEFAULT' . Util
::getCharsetQueryPart($_POST['db_collation']);
92 $result = $GLOBALS['dbi']->query($sql_query);
93 $message = Message
::success();
96 * Changes tables charset if requested by the user
99 isset($_POST['change_all_tables_collations']) &&
100 $_POST['change_all_tables_collations'] === 'on'
102 list($tables, , , , , , , ,) = PhpMyAdmin\Util
::getDbInfo($db, null);
103 foreach($tables as $tableName => $data) {
104 if ($GLOBALS['dbi']->getTable($db, $tableName)->isView()) {
105 // Skip views, we can not change the collation of a view.
109 $sql_query = 'ALTER TABLE '
110 . PhpMyAdmin\Util
::backquote($db)
112 . PhpMyAdmin\Util
::backquote($tableName)
114 . Util
::getCharsetQueryPart($_POST['db_collation']);
115 $GLOBALS['dbi']->query($sql_query);
118 * Changes columns charset if requested by the user
121 isset($_POST['change_all_tables_columns_collations']) &&
122 $_POST['change_all_tables_columns_collations'] === 'on'
124 $operations = new Operations();
125 $operations->changeAllColumnsCollation($db, $tableName, $_POST['db_collation']);
133 * If we are in an Ajax request, let us stop the execution here. Necessary for
134 * db charset change action on db_operations.php. If this causes a bug on
135 * other pages, we might have to move this to a different location.
137 if ($response->isAjax()) {
138 $response->setRequestStatus($message->isSuccess());
139 $response->addJSON('message', $message);
142 } elseif (isset($_POST['submitcollation'])
143 && isset($_POST['db_collation'])
144 && empty($_POST['db_collation'])
146 $response = Response
::getInstance();
147 if ($response->isAjax()) {
148 $response->setRequestStatus(false);
151 Message
::error(__('No collation provided.'))
157 * Set parameters for links
159 $url_query = Url
::getCommon(array('db' => $db));