Translated using Weblate (Turkish)
[phpmyadmin.git] / libraries / db_common.inc.php
blobab6f6936151431edc57c6ad6f641132bbb0f695d
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'] . '?' . PMA_URL_getCommon($db);
33 /**
34 * Ensures the database exists (else move to the "parent" script) and displays
35 * headers
37 if (! isset($is_db) || ! $is_db) {
38 if (strlen($db)) {
39 $is_db = $GLOBALS['dbi']->selectDb($db);
40 // This "Command out of sync" 2014 error may happen, for example
41 // after calling a MySQL procedure; at this point we can't select
42 // the db but it's not necessarily wrong
43 if ($GLOBALS['dbi']->getError() && $GLOBALS['errno'] == 2014) {
44 $is_db = true;
45 unset($GLOBALS['errno']);
47 } else {
48 $is_db = false;
50 // Not a valid db name -> back to the welcome page
51 $uri = $cfg['PmaAbsoluteUri'] . 'index.php?'
52 . PMA_URL_getCommon('', '', '&')
53 . (isset($message) ? '&message=' . urlencode($message) : '') . '&reload=1';
54 if (! strlen($db) || ! $is_db) {
55 $response = PMA_Response::getInstance();
56 if ($response->isAjax()) {
57 $response->isSuccess(false);
58 $response->addJSON(
59 'message',
60 PMA_Message::error(__('No databases selected.'))
62 } else {
63 PMA_sendHeaderLocation($uri);
65 exit;
67 } // end if (ensures db exists)
69 /**
70 * Changes database charset if requested by the user
72 if (isset($_REQUEST['submitcollation'])
73 && isset($_REQUEST['db_collation'])
74 && ! empty($_REQUEST['db_collation'])
75 ) {
76 list($db_charset) = explode('_', $_REQUEST['db_collation']);
77 $sql_query = 'ALTER DATABASE '
78 . PMA_Util::backquote($db)
79 . ' DEFAULT' . PMA_generateCharsetQueryPart($_REQUEST['db_collation']);
80 $result = $GLOBALS['dbi']->query($sql_query);
81 $message = PMA_Message::success();
82 unset($db_charset);
84 /**
85 * If we are in an Ajax request, let us stop the execution here. Necessary for
86 * db charset change action on db_operations.php. If this causes a bug on
87 * other pages, we might have to move this to a different location.
89 if ( $GLOBALS['is_ajax_request'] == true) {
90 $response = PMA_Response::getInstance();
91 $response->isSuccess($message->isSuccess());
92 $response->addJSON('message', $message);
93 exit;
97 /**
98 * Set parameters for links
100 $url_query = PMA_URL_getCommon($db);