Translated using Weblate (Finnish)
[phpmyadmin.git] / libraries / db_common.inc.php
blobbf40fc028c8a3e5b0ee7e3300e4e45b6ff79c1f9
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 if (! defined('PHPMYADMIN')) {
9 exit;
12 /**
13 * Gets some core libraries
15 require_once './libraries/bookmark.lib.php';
17 PMA_Util::checkParameters(array('db'));
19 $is_show_stats = $cfg['ShowStats'];
21 $db_is_system_schema = $GLOBALS['dbi']->isSystemSchema($db);
22 if ($db_is_system_schema) {
23 $is_show_stats = false;
26 /**
27 * Defines the urls to return to in case of error in a sql statement
29 $err_url_0 = 'index.php' . PMA_URL_getCommon();
30 $err_url = $cfg['DefaultTabDatabase']
31 . PMA_URL_getCommon(array('db' => $db));
33 /** @var PMA_String $pmaString */
34 $pmaString = $GLOBALS['PMA_String'];
36 /**
37 * Ensures the database exists (else move to the "parent" script) and displays
38 * headers
40 if (! isset($is_db) || ! $is_db) {
41 if (/*overload*/mb_strlen($db)) {
42 $is_db = $GLOBALS['dbi']->selectDb($db);
43 // This "Command out of sync" 2014 error may happen, for example
44 // after calling a MySQL procedure; at this point we can't select
45 // the db but it's not necessarily wrong
46 if ($GLOBALS['dbi']->getError() && $GLOBALS['errno'] == 2014) {
47 $is_db = true;
48 unset($GLOBALS['errno']);
50 } else {
51 $is_db = false;
53 // Not a valid db name -> back to the welcome page
54 $uri = $cfg['PmaAbsoluteUri'] . 'index.php'
55 . PMA_URL_getCommon(array(), 'text')
56 . (isset($message) ? '&message=' . urlencode($message) : '') . '&reload=1';
57 if (!/*overload*/mb_strlen($db) || ! $is_db) {
58 $response = PMA_Response::getInstance();
59 if ($response->isAjax()) {
60 $response->isSuccess(false);
61 $response->addJSON(
62 'message',
63 PMA_Message::error(__('No databases selected.'))
65 } else {
66 PMA_sendHeaderLocation($uri);
68 exit;
70 } // end if (ensures db exists)
72 /**
73 * Changes database charset if requested by the user
75 if (isset($_REQUEST['submitcollation'])
76 && isset($_REQUEST['db_collation'])
77 && ! empty($_REQUEST['db_collation'])
78 ) {
79 list($db_charset) = explode('_', $_REQUEST['db_collation']);
80 $sql_query = 'ALTER DATABASE '
81 . PMA_Util::backquote($db)
82 . ' DEFAULT' . PMA_generateCharsetQueryPart($_REQUEST['db_collation']);
83 $result = $GLOBALS['dbi']->query($sql_query);
84 $message = PMA_Message::success();
85 unset($db_charset);
87 /**
88 * If we are in an Ajax request, let us stop the execution here. Necessary for
89 * db charset change action on db_operations.php. If this causes a bug on
90 * other pages, we might have to move this to a different location.
92 if ( $GLOBALS['is_ajax_request'] == true) {
93 $response = PMA_Response::getInstance();
94 $response->isSuccess($message->isSuccess());
95 $response->addJSON('message', $message);
96 exit;
101 * Set parameters for links
103 $url_query = PMA_URL_getCommon(array('db' => $db));