Translated using Weblate (Dutch)
[phpmyadmin.git] / libraries / db_common.inc.php
blob0e6c73c4b1c54659ee6aa94f69c75e1c5fae74a7
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 PMA\libraries\Core;
10 use PMA\libraries\Message;
11 use PMA\libraries\Response;
12 use PMA\libraries\URL;
13 use PMA\libraries\Util;
15 if (! defined('PHPMYADMIN')) {
16 exit;
19 PMA\libraries\Util::checkParameters(array('db'));
21 global $cfg;
22 global $db;
24 $response = Response::getInstance();
25 $is_show_stats = $cfg['ShowStats'];
27 $db_is_system_schema = $GLOBALS['dbi']->isSystemSchema($db);
28 if ($db_is_system_schema) {
29 $is_show_stats = false;
32 /**
33 * Defines the urls to return to in case of error in a sql statement
35 $err_url_0 = 'index.php' . URL::getCommon();
37 $err_url = PMA\libraries\Util::getScriptNameForOption(
38 $GLOBALS['cfg']['DefaultTabDatabase'], 'database'
40 . URL::getCommon(array('db' => $db));
42 /**
43 * Ensures the database exists (else move to the "parent" script) and displays
44 * headers
46 if (! isset($is_db) || ! $is_db) {
47 if (strlen($db) > 0) {
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) {
53 $is_db = true;
54 unset($GLOBALS['errno']);
56 } else {
57 $is_db = false;
59 // Not a valid db name -> back to the welcome page
60 $params = array('reload' => '1');
61 if (isset($message)) {
62 $params['message'] = $message;
64 $uri = './index.php' . URL::getCommonRaw($params);
65 if (strlen($db) === 0 || ! $is_db) {
66 $response = Response::getInstance();
67 if ($response->isAjax()) {
68 $response->setRequestStatus(false);
69 $response->addJSON(
70 'message',
71 Message::error(__('No databases selected.'))
73 } else {
74 Core::sendHeaderLocation($uri);
76 exit;
78 } // end if (ensures db exists)
80 /**
81 * Changes database charset if requested by the user
83 if (isset($_REQUEST['submitcollation'])
84 && isset($_REQUEST['db_collation'])
85 && ! empty($_REQUEST['db_collation'])
86 ) {
87 list($db_charset) = explode('_', $_REQUEST['db_collation']);
88 $sql_query = 'ALTER DATABASE '
89 . PMA\libraries\Util::backquote($db)
90 . ' DEFAULT' . Util::getCharsetQueryPart($_REQUEST['db_collation']);
91 $result = $GLOBALS['dbi']->query($sql_query);
92 $message = Message::success();
93 unset($db_charset);
95 /**
96 * If we are in an Ajax request, let us stop the execution here. Necessary for
97 * db charset change action on db_operations.php. If this causes a bug on
98 * other pages, we might have to move this to a different location.
100 if ($response->isAjax()) {
101 $response->setRequestStatus($message->isSuccess());
102 $response->addJSON('message', $message);
103 exit;
108 * Set parameters for links
110 $url_query = URL::getCommon(array('db' => $db));