Translated using Weblate (Ukrainian)
[phpmyadmin.git] / libraries / db_common.inc.php
blobbca8f2d07dedeeaf2068f30ead709c95f1f6ed58
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 /**
4 * Common includes for the database level views
6 * @package PhpMyAdmin
7 */
9 use PhpMyAdmin\Core;
10 use PhpMyAdmin\Message;
11 use PhpMyAdmin\Response;
12 use PhpMyAdmin\Url;
13 use PhpMyAdmin\Util;
14 use PhpMyAdmin\Operations;
16 if (! defined('PHPMYADMIN')) {
17 exit;
20 PhpMyAdmin\Util::checkParameters(array('db'));
22 global $cfg;
23 global $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;
33 /**
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));
43 /**
44 * Ensures the database exists (else move to the "parent" script) and displays
45 * headers
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) {
54 $is_db = true;
55 unset($GLOBALS['errno']);
57 } else {
58 $is_db = false;
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);
70 $response->addJSON(
71 'message',
72 Message::error(__('No databases selected.'))
74 } else {
75 Core::sendHeaderLocation($uri);
77 exit;
79 } // end if (ensures db exists)
81 /**
82 * Changes database charset if requested by the user
84 if (isset($_REQUEST['submitcollation'])
85 && isset($_REQUEST['db_collation'])
86 && ! empty($_REQUEST['db_collation'])
87 ) {
88 list($db_charset) = explode('_', $_REQUEST['db_collation']);
89 $sql_query = 'ALTER DATABASE '
90 . PhpMyAdmin\Util::backquote($db)
91 . ' DEFAULT' . Util::getCharsetQueryPart($_REQUEST['db_collation']);
92 $result = $GLOBALS['dbi']->query($sql_query);
93 $message = Message::success();
95 /**
96 * Changes tables charset if requested by the user
98 if (
99 isset($_REQUEST['change_all_tables_collations']) &&
100 $_REQUEST['change_all_tables_collations'] == 'on'
102 list($tables, , , , , , , ,) = PhpMyAdmin\Util::getDbInfo($db, null);
103 foreach($tables as $tableName => $data) {
104 $sql_query = 'ALTER TABLE '
105 . PhpMyAdmin\Util::backquote($db)
106 . '.'
107 . PhpMyAdmin\Util::backquote($tableName)
108 . 'DEFAULT '
109 . Util::getCharsetQueryPart($_REQUEST['db_collation']);
110 $GLOBALS['dbi']->query($sql_query);
113 * Changes columns charset if requested by the user
115 if (
116 isset($_REQUEST['change_all_tables_columns_collations']) &&
117 $_REQUEST['change_all_tables_columns_collations'] == 'on'
119 $operations = new Operations();
120 $operations->changeAllColumnsCollation($db, $tableName, $_REQUEST['db_collation']);
125 unset($db_charset);
128 * If we are in an Ajax request, let us stop the execution here. Necessary for
129 * db charset change action on db_operations.php. If this causes a bug on
130 * other pages, we might have to move this to a different location.
132 if ($response->isAjax()) {
133 $response->setRequestStatus($message->isSuccess());
134 $response->addJSON('message', $message);
135 exit;
140 * Set parameters for links
142 $url_query = Url::getCommon(array('db' => $db));