Translated using Weblate (Chinese (Traditional))
[phpmyadmin.git] / libraries / db_common.inc.php
blob4d5a92acf959c9e1962944ae790428443c495829
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 $params = array('reload' => '1');
59 if (isset($message)) {
60 $params['message'] = $message;
62 $uri = './index.php' . URL::getCommonRaw($params);
63 if (strlen($db) === 0 || ! $is_db) {
64 $response = Response::getInstance();
65 if ($response->isAjax()) {
66 $response->setRequestStatus(false);
67 $response->addJSON(
68 'message',
69 Message::error(__('No databases selected.'))
71 } else {
72 PMA_sendHeaderLocation($uri);
74 exit;
76 } // end if (ensures db exists)
78 /**
79 * Changes database charset if requested by the user
81 if (isset($_REQUEST['submitcollation'])
82 && isset($_REQUEST['db_collation'])
83 && ! empty($_REQUEST['db_collation'])
84 ) {
85 list($db_charset) = explode('_', $_REQUEST['db_collation']);
86 $sql_query = 'ALTER DATABASE '
87 . PMA\libraries\Util::backquote($db)
88 . ' DEFAULT' . Util::getCharsetQueryPart($_REQUEST['db_collation']);
89 $result = $GLOBALS['dbi']->query($sql_query);
90 $message = Message::success();
91 unset($db_charset);
93 /**
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 ($response->isAjax()) {
99 $response->setRequestStatus($message->isSuccess());
100 $response->addJSON('message', $message);
101 exit;
106 * Set parameters for links
108 $url_query = URL::getCommon(array('db' => $db));