Translated using Weblate (Slovenian)
[phpmyadmin.git] / libraries / db_common.inc.php
blob5f9364d1a312d3c3037083fe03d86de8bb7c680a
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 */
8 use PMA\libraries\Message;
9 use PMA\libraries\Response;
10 use PMA\libraries\URL;
11 use PMA\libraries\Util;
13 if (! defined('PHPMYADMIN')) {
14 exit;
17 PMA\libraries\Util::checkParameters(array('db'));
19 global $cfg;
20 global $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;
30 /**
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));
40 /**
41 * Ensures the database exists (else move to the "parent" script) and displays
42 * headers
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) {
51 $is_db = true;
52 unset($GLOBALS['errno']);
54 } else {
55 $is_db = false;
57 // Not a valid db name -> back to the welcome page
58 $uri = './index.php'
59 . URL::getCommonRaw(array())
60 . (isset($message) ? '&message=' . urlencode($message) : '') . '&reload=1';
61 if (strlen($db) === 0 || ! $is_db) {
62 $response = Response::getInstance();
63 if ($response->isAjax()) {
64 $response->setRequestStatus(false);
65 $response->addJSON(
66 'message',
67 Message::error(__('No databases selected.'))
69 } else {
70 PMA_sendHeaderLocation($uri);
72 exit;
74 } // end if (ensures db exists)
76 /**
77 * Changes database charset if requested by the user
79 if (isset($_REQUEST['submitcollation'])
80 && isset($_REQUEST['db_collation'])
81 && ! empty($_REQUEST['db_collation'])
82 ) {
83 list($db_charset) = explode('_', $_REQUEST['db_collation']);
84 $sql_query = 'ALTER DATABASE '
85 . PMA\libraries\Util::backquote($db)
86 . ' DEFAULT' . Util::getCharsetQueryPart($_REQUEST['db_collation']);
87 $result = $GLOBALS['dbi']->query($sql_query);
88 $message = Message::success();
89 unset($db_charset);
91 /**
92 * If we are in an Ajax request, let us stop the execution here. Necessary for
93 * db charset change action on db_operations.php. If this causes a bug on
94 * other pages, we might have to move this to a different location.
96 if ($response->isAjax()) {
97 $response->setRequestStatus($message->isSuccess());
98 $response->addJSON('message', $message);
99 exit;
104 * Set parameters for links
106 $url_query = URL::getCommon(array('db' => $db));