diff --git a/browse_foreigners.php b/browse_foreigners.php index 8023917d3f..6da290d503 100644 --- a/browse_foreigners.php +++ b/browse_foreigners.php @@ -36,7 +36,7 @@ $header = $response->getHeader(); $header->disableMenuAndConsole(); $header->setBodyId('body_browse_foreigners'); -$relation = new Relation(); +$relation = new Relation($GLOBALS['dbi']); /** * Displays the frame diff --git a/chk_rel.php b/chk_rel.php index d4724ef2f9..cd625fff32 100644 --- a/chk_rel.php +++ b/chk_rel.php @@ -12,7 +12,7 @@ use PhpMyAdmin\Response; require_once 'libraries/common.inc.php'; -$relation = new Relation(); +$relation = new Relation($GLOBALS['dbi']); // If request for creating the pmadb if (isset($_REQUEST['create_pmadb'])) { diff --git a/db_datadict.php b/db_datadict.php index 621011acfd..76926ae8b2 100644 --- a/db_datadict.php +++ b/db_datadict.php @@ -36,7 +36,7 @@ $response = Response::getInstance(); $header = $response->getHeader(); $header->enablePrintView(); -$relation = new Relation(); +$relation = new Relation($GLOBALS['dbi']); $transformations = new Transformations(); /** diff --git a/db_operations.php b/db_operations.php index f1871547e0..510b524aeb 100644 --- a/db_operations.php +++ b/db_operations.php @@ -216,7 +216,7 @@ if (strlen($GLOBALS['db']) > 0 /** * Settings for relations stuff */ -$relation = new Relation(); +$relation = new Relation($GLOBALS['dbi']); $cfgRelation = $relation->getRelationsParam(); diff --git a/db_qbe.php b/db_qbe.php index 20f32b9b37..82a8d3b980 100644 --- a/db_qbe.php +++ b/db_qbe.php @@ -24,7 +24,7 @@ require_once 'libraries/common.inc.php'; $response = Response::getInstance(); // Gets the relation settings -$relation = new Relation(); +$relation = new Relation($GLOBALS['dbi']); $cfgRelation = $relation->getRelationsParam(); $savedSearchList = []; diff --git a/export.php b/export.php index bf142267c6..86d62c3d82 100644 --- a/export.php +++ b/export.php @@ -408,7 +408,7 @@ if ($save_on_server) { } // end download } -$relation = new Relation(); +$relation = new Relation($GLOBALS['dbi']); // Fake loop just to allow skip of remain of this code by break, I'd really // need exceptions here :-) diff --git a/index.php b/index.php index d7c0a9a3bf..6ab209e1a8 100644 --- a/index.php +++ b/index.php @@ -604,7 +604,7 @@ if (@file_exists('config')) { ); } -$relation = new Relation(); +$relation = new Relation($GLOBALS['dbi']); if ($server > 0) { $cfgRelation = $relation->getRelationsParam(); diff --git a/libraries/classes/Bookmark.php b/libraries/classes/Bookmark.php index ceb1c2559a..8ac0405adb 100644 --- a/libraries/classes/Bookmark.php +++ b/libraries/classes/Bookmark.php @@ -228,7 +228,7 @@ class Bookmark return $cfgBookmark; } - $relation = new Relation(); + $relation = new Relation($GLOBALS['dbi']); $cfgRelation = $relation->getRelationsParam(); if ($cfgRelation['bookmarkwork']) { $cfgBookmark = [ diff --git a/libraries/classes/CentralColumns.php b/libraries/classes/CentralColumns.php index c8df7d4119..4204ff37e7 100644 --- a/libraries/classes/CentralColumns.php +++ b/libraries/classes/CentralColumns.php @@ -83,7 +83,7 @@ class CentralColumns $this->charEditing = $GLOBALS['cfg']['CharEditing']; $this->disableIs = (bool) $GLOBALS['cfg']['Server']['DisableIS']; - $this->relation = new Relation(); + $this->relation = new Relation($this->dbi); $this->template = new Template(); } diff --git a/libraries/classes/Console.php b/libraries/classes/Console.php index 48dac1c2ad..50ac77a243 100644 --- a/libraries/classes/Console.php +++ b/libraries/classes/Console.php @@ -53,7 +53,7 @@ class Console public function __construct() { $this->_isEnabled = true; - $this->relation = new Relation(); + $this->relation = new Relation($GLOBALS['dbi']); $this->template = new Template(); } diff --git a/libraries/classes/Controllers/Database/DatabaseStructureController.php b/libraries/classes/Controllers/Database/DatabaseStructureController.php index 6c641c55d8..ed0638f50f 100644 --- a/libraries/classes/Controllers/Database/DatabaseStructureController.php +++ b/libraries/classes/Controllers/Database/DatabaseStructureController.php @@ -78,7 +78,7 @@ class DatabaseStructureController extends DatabaseController public function __construct($response, $dbi, $db) { parent::__construct($response, $dbi, $db); - $this->relation = new Relation(); + $this->relation = new Relation($dbi); $this->replication = new Replication(); } diff --git a/libraries/classes/Controllers/Table/TableRelationController.php b/libraries/classes/Controllers/Table/TableRelationController.php index e71f2547fb..09c028e109 100644 --- a/libraries/classes/Controllers/Table/TableRelationController.php +++ b/libraries/classes/Controllers/Table/TableRelationController.php @@ -94,7 +94,7 @@ class TableRelationController extends TableController $this->existrel = $existrel; $this->existrel_foreign = $existrel_foreign; $this->upd_query = $upd_query; - $this->relation = new Relation(); + $this->relation = new Relation($dbi); } /** diff --git a/libraries/classes/Controllers/Table/TableSearchController.php b/libraries/classes/Controllers/Table/TableSearchController.php index 11f84b602c..ac896961bf 100644 --- a/libraries/classes/Controllers/Table/TableSearchController.php +++ b/libraries/classes/Controllers/Table/TableSearchController.php @@ -115,7 +115,7 @@ class TableSearchController extends TableController $this->_columnCollations = []; $this->_geomColumnFlag = false; $this->_foreigners = []; - $this->relation = new Relation(); + $this->relation = new Relation($dbi); // Loads table's information $this->_loadTableInfo(); $this->_connectionCharSet = $this->dbi->fetchValue( diff --git a/libraries/classes/Controllers/Table/TableStructureController.php b/libraries/classes/Controllers/Table/TableStructureController.php index 142cd81f19..60b0e1b194 100644 --- a/libraries/classes/Controllers/Table/TableStructureController.php +++ b/libraries/classes/Controllers/Table/TableStructureController.php @@ -135,7 +135,7 @@ class TableStructureController extends TableController $this->table_obj = $this->dbi->getTable($this->db, $this->table); $this->createAddField = new CreateAddField($dbi); - $this->relation = new Relation(); + $this->relation = new Relation($dbi); $this->transformations = new Transformations(); } diff --git a/libraries/classes/Database/Designer.php b/libraries/classes/Database/Designer.php index 7407933ec7..c5fde12d23 100644 --- a/libraries/classes/Database/Designer.php +++ b/libraries/classes/Database/Designer.php @@ -47,7 +47,7 @@ class Designer public function __construct(DatabaseInterface $dbi) { $this->dbi = $dbi; - $this->relation = new Relation(); + $this->relation = new Relation($this->dbi); $this->template = new Template(); } diff --git a/libraries/classes/Database/Designer/Common.php b/libraries/classes/Database/Designer/Common.php index dad3aee7f3..ec22460ff4 100644 --- a/libraries/classes/Database/Designer/Common.php +++ b/libraries/classes/Database/Designer/Common.php @@ -40,7 +40,7 @@ class Common public function __construct(DatabaseInterface $dbi) { $this->dbi = $dbi; - $this->relation = new Relation(); + $this->relation = new Relation($this->dbi); } /** diff --git a/libraries/classes/Database/Qbe.php b/libraries/classes/Database/Qbe.php index 137196e094..ee8df79926 100644 --- a/libraries/classes/Database/Qbe.php +++ b/libraries/classes/Database/Qbe.php @@ -248,8 +248,8 @@ class Qbe $this->_db = $dbname; $this->_savedSearchList = $savedSearchList; $this->_currentSearch = $currentSearch; - $this->relation = new Relation(); $this->dbi = $dbi; + $this->relation = new Relation($this->dbi); $this->template = new Template(); $this->_loadCriterias(); diff --git a/libraries/classes/DatabaseInterface.php b/libraries/classes/DatabaseInterface.php index 01e1b08c11..dd2d5ac870 100644 --- a/libraries/classes/DatabaseInterface.php +++ b/libraries/classes/DatabaseInterface.php @@ -139,7 +139,7 @@ class DatabaseInterface $this->_table_cache = []; $this->_current_user = []; $this->types = new Types($this); - $this->relation = new Relation(); + $this->relation = new Relation($this); } /** diff --git a/libraries/classes/Display/Export.php b/libraries/classes/Display/Export.php index 2641a785e8..37d9fa1362 100644 --- a/libraries/classes/Display/Export.php +++ b/libraries/classes/Display/Export.php @@ -44,7 +44,7 @@ class Export */ public function __construct() { - $this->relation = new Relation(); + $this->relation = new Relation($GLOBALS['dbi']); $this->template = new Template(); } diff --git a/libraries/classes/Display/Results.php b/libraries/classes/Display/Results.php index 4fbfa9f8fe..cddec4086b 100644 --- a/libraries/classes/Display/Results.php +++ b/libraries/classes/Display/Results.php @@ -214,7 +214,7 @@ class Results */ public function __construct($db, $table, $goto, $sql_query) { - $this->relation = new Relation(); + $this->relation = new Relation($GLOBALS['dbi']); $this->transformations = new Transformations(); $this->template = new Template(); diff --git a/libraries/classes/ErrorReport.php b/libraries/classes/ErrorReport.php index fc0fd15562..fca2798ab6 100644 --- a/libraries/classes/ErrorReport.php +++ b/libraries/classes/ErrorReport.php @@ -52,7 +52,7 @@ class ErrorReport { $this->httpRequest = $httpRequest; $this->submissionUrl = 'https://reports.phpmyadmin.net/incidents/create'; - $this->relation = new Relation(); + $this->relation = new Relation($GLOBALS['dbi']); $this->template = new Template(); } diff --git a/libraries/classes/Footer.php b/libraries/classes/Footer.php index 35ba8ded99..8c00cc44b8 100644 --- a/libraries/classes/Footer.php +++ b/libraries/classes/Footer.php @@ -70,7 +70,7 @@ class Footer $this->_isEnabled = true; $this->_scripts = new Scripts(); $this->_isMinimal = false; - $this->relation = new Relation(); + $this->relation = new Relation($GLOBALS['dbi']); } /** diff --git a/libraries/classes/InsertEdit.php b/libraries/classes/InsertEdit.php index 08a16c3bdf..93f55f2b4c 100644 --- a/libraries/classes/InsertEdit.php +++ b/libraries/classes/InsertEdit.php @@ -63,7 +63,7 @@ class InsertEdit public function __construct(DatabaseInterface $dbi) { $this->dbi = $dbi; - $this->relation = new Relation(); + $this->relation = new Relation($GLOBALS['dbi']); $this->transformations = new Transformations(); $this->fileListing = new FileListing(); $this->template = new Template(); diff --git a/libraries/classes/Menu.php b/libraries/classes/Menu.php index 97bb0bc80e..0737a76334 100644 --- a/libraries/classes/Menu.php +++ b/libraries/classes/Menu.php @@ -61,7 +61,7 @@ class Menu $this->_server = $server; $this->_db = $db; $this->_table = $table; - $this->relation = new Relation(); + $this->relation = new Relation($GLOBALS['dbi']); } /** diff --git a/libraries/classes/Navigation/Navigation.php b/libraries/classes/Navigation/Navigation.php index 7075fdaff8..8f1bc5ca1b 100644 --- a/libraries/classes/Navigation/Navigation.php +++ b/libraries/classes/Navigation/Navigation.php @@ -27,14 +27,14 @@ class Navigation /** * @var Relation $relation */ - private $relation; + public $relation; /** * Constructor */ public function __construct() { - $this->relation = new Relation(); + $this->relation = new Relation($GLOBALS['dbi']); } /** diff --git a/libraries/classes/Navigation/Nodes/Node.php b/libraries/classes/Navigation/Nodes/Node.php index 2327224604..6772a40ade 100644 --- a/libraries/classes/Navigation/Nodes/Node.php +++ b/libraries/classes/Navigation/Nodes/Node.php @@ -127,7 +127,7 @@ class Node $this->type = Node::CONTAINER; } $this->is_group = (bool)$is_group; - $this->relation = new Relation(); + $this->relation = new Relation($GLOBALS['dbi']); } /** diff --git a/libraries/classes/Normalization.php b/libraries/classes/Normalization.php index 0645131f73..488c9ae7e5 100644 --- a/libraries/classes/Normalization.php +++ b/libraries/classes/Normalization.php @@ -54,7 +54,7 @@ class Normalization public function __construct(DatabaseInterface $dbi) { $this->dbi = $dbi; - $this->relation = new Relation(); + $this->relation = new Relation($this->dbi); $this->transformations = new Transformations(); $this->template = new Template(); } diff --git a/libraries/classes/Operations.php b/libraries/classes/Operations.php index f8487952a9..f88e2f2d9d 100644 --- a/libraries/classes/Operations.php +++ b/libraries/classes/Operations.php @@ -39,7 +39,7 @@ class Operations */ public function __construct() { - $this->relation = new Relation(); + $this->relation = new Relation($GLOBALS['dbi']); } /** diff --git a/libraries/classes/Plugins/Export/Helpers/Pdf.php b/libraries/classes/Plugins/Export/Helpers/Pdf.php index 8ace9305e2..fac48e0c86 100644 --- a/libraries/classes/Plugins/Export/Helpers/Pdf.php +++ b/libraries/classes/Plugins/Export/Helpers/Pdf.php @@ -90,7 +90,7 @@ class Pdf extends PdfLib $diskcache, $pdfa ); - $this->relation = new Relation(); + $this->relation = new Relation($GLOBALS['dbi']); $this->transformations = new Transformations(); } diff --git a/libraries/classes/Plugins/ExportPlugin.php b/libraries/classes/Plugins/ExportPlugin.php index f356410df3..71eee3820d 100644 --- a/libraries/classes/Plugins/ExportPlugin.php +++ b/libraries/classes/Plugins/ExportPlugin.php @@ -35,7 +35,7 @@ abstract class ExportPlugin /** * @var Relation $relation */ - protected $relation; + public $relation; /** * @var Export $export @@ -52,7 +52,7 @@ abstract class ExportPlugin */ public function __construct() { - $this->relation = new Relation(); + $this->relation = new Relation($GLOBALS['dbi']); $this->export = new Export(); $this->transformations = new Transformations(); } diff --git a/libraries/classes/Plugins/Schema/ExportRelationSchema.php b/libraries/classes/Plugins/Schema/ExportRelationSchema.php index 4b11ba3cb3..4b6962c59f 100644 --- a/libraries/classes/Plugins/Schema/ExportRelationSchema.php +++ b/libraries/classes/Plugins/Schema/ExportRelationSchema.php @@ -51,7 +51,7 @@ class ExportRelationSchema $this->diagram = $diagram; $this->setPageNumber($_REQUEST['page_number']); $this->setOffline(isset($_REQUEST['offline_export'])); - $this->relation = new Relation(); + $this->relation = new Relation($GLOBALS['dbi']); } /** diff --git a/libraries/classes/Plugins/Schema/Pdf/Pdf.php b/libraries/classes/Plugins/Schema/Pdf/Pdf.php index f709d18711..12de3a5216 100644 --- a/libraries/classes/Plugins/Schema/Pdf/Pdf.php +++ b/libraries/classes/Plugins/Schema/Pdf/Pdf.php @@ -86,7 +86,7 @@ class Pdf extends PdfLib $this->_pageNumber = $pageNumber; $this->_withDoc = $withDoc; $this->_db = $db; - $this->relation = new Relation(); + $this->relation = new Relation($GLOBALS['dbi']); } /** diff --git a/libraries/classes/Plugins/Schema/TableStats.php b/libraries/classes/Plugins/Schema/TableStats.php index 9130043264..2ddbd8ada2 100644 --- a/libraries/classes/Plugins/Schema/TableStats.php +++ b/libraries/classes/Plugins/Schema/TableStats.php @@ -83,7 +83,7 @@ abstract class TableStats $this->offline = $offline; - $this->relation = new Relation(); + $this->relation = new Relation($GLOBALS['dbi']); $this->font = new Font(); // checks whether the table exists diff --git a/libraries/classes/RecentFavoriteTable.php b/libraries/classes/RecentFavoriteTable.php index 96f6cf0bc3..a16aafa4c7 100644 --- a/libraries/classes/RecentFavoriteTable.php +++ b/libraries/classes/RecentFavoriteTable.php @@ -63,7 +63,7 @@ class RecentFavoriteTable */ private function __construct($type) { - $this->relation = new Relation(); + $this->relation = new Relation($GLOBALS['dbi']); $this->_tableType = $type; $server_id = $GLOBALS['server']; if (! isset($_SESSION['tmpval'][$this->_tableType . '_tables'][$server_id]) diff --git a/libraries/classes/Relation.php b/libraries/classes/Relation.php index e420392b6d..d6fc41fa78 100644 --- a/libraries/classes/Relation.php +++ b/libraries/classes/Relation.php @@ -27,6 +27,11 @@ use PhpMyAdmin\Util; */ class Relation { + /** + * @var DatabaseInterface + */ + public $dbi; + /** * @var Template */ @@ -34,9 +39,12 @@ class Relation /** * Relation constructor. + * + * @param DatabaseInterface $dbi Database interface */ - public function __construct() + public function __construct(DatabaseInterface $dbi) { + $this->dbi = $dbi; $this->template = new Template(); } @@ -61,14 +69,14 @@ class Relation $cache_affected_rows = false; if ($show_error) { - $result = $GLOBALS['dbi']->query( + $result = $this->dbi->query( $sql, DatabaseInterface::CONNECT_CONTROL, $options, $cache_affected_rows ); } else { - $result = @$GLOBALS['dbi']->tryQuery( + $result = @$this->dbi->tryQuery( $sql, DatabaseInterface::CONNECT_CONTROL, $options, @@ -515,7 +523,7 @@ class Relation if ($GLOBALS['server'] == 0 || empty($GLOBALS['cfg']['Server']['pmadb']) - || ! $GLOBALS['dbi']->selectDb( + || ! $this->dbi->selectDb( $GLOBALS['cfg']['Server']['pmadb'], DatabaseInterface::CONNECT_CONTROL ) @@ -551,7 +559,7 @@ class Relation return $cfgRelation; } - while ($curr_table = @$GLOBALS['dbi']->fetchRow($tab_rs)) { + while ($curr_table = @$this->dbi->fetchRow($tab_rs)) { if ($curr_table[0] == $GLOBALS['cfg']['Server']['bookmarktable']) { $cfgRelation['bookmark'] = $curr_table[0]; } elseif ($curr_table[0] == $GLOBALS['cfg']['Server']['relation']) { @@ -592,7 +600,7 @@ class Relation $cfgRelation['export_templates'] = $curr_table[0]; } } // end while - $GLOBALS['dbi']->freeResult($tab_rs); + $this->dbi->freeResult($tab_rs); if (isset($cfgRelation['relation'])) { $cfgRelation['relwork'] = true; @@ -725,8 +733,8 @@ class Relation DatabaseInterface::QUERY_STORE ); if ($result) { - $rows = $GLOBALS['dbi']->numRows($result); - $GLOBALS['dbi']->freeResult($result); + $rows = $this->dbi->numRows($result); + $this->dbi->freeResult($result); // input transformations are present // no need to upgrade if ($rows === 2) { @@ -751,13 +759,13 @@ class Relation ), $query ); - $GLOBALS['dbi']->tryMultiQuery($query, DatabaseInterface::CONNECT_CONTROL); + $this->dbi->tryMultiQuery($query, DatabaseInterface::CONNECT_CONTROL); // skips result sets of query as we are not interested in it - while ($GLOBALS['dbi']->moreResults(DatabaseInterface::CONNECT_CONTROL) - && $GLOBALS['dbi']->nextResult(DatabaseInterface::CONNECT_CONTROL) + while ($this->dbi->moreResults(DatabaseInterface::CONNECT_CONTROL) + && $this->dbi->nextResult(DatabaseInterface::CONNECT_CONTROL) ) { } - $error = $GLOBALS['dbi']->getError(DatabaseInterface::CONNECT_CONTROL); + $error = $this->dbi->getError(DatabaseInterface::CONNECT_CONTROL); // return true if no error exists otherwise false return empty($error); } @@ -792,14 +800,14 @@ class Relation `foreign_field` FROM ' . Util::backquote($cfgRelation['db']) . '.' . Util::backquote($cfgRelation['relation']) . ' - WHERE `master_db` = \'' . $GLOBALS['dbi']->escapeString($db) . '\' - AND `master_table` = \'' . $GLOBALS['dbi']->escapeString($table) + WHERE `master_db` = \'' . $this->dbi->escapeString($db) . '\' + AND `master_table` = \'' . $this->dbi->escapeString($table) . '\' '; if (strlen($column) > 0) { $rel_query .= ' AND `master_field` = ' - . '\'' . $GLOBALS['dbi']->escapeString($column) . '\''; + . '\'' . $this->dbi->escapeString($column) . '\''; } - $foreign = $GLOBALS['dbi']->fetchResult( + $foreign = $this->dbi->fetchResult( $rel_query, 'master_field', null, @@ -874,11 +882,11 @@ class Relation SELECT `display_field` FROM ' . Util::backquote($cfgRelation['db']) . '.' . Util::backquote($cfgRelation['table_info']) . ' - WHERE `db_name` = \'' . $GLOBALS['dbi']->escapeString((string)$db) . '\' - AND `table_name` = \'' . $GLOBALS['dbi']->escapeString((string)$table) + WHERE `db_name` = \'' . $this->dbi->escapeString((string)$db) . '\' + AND `table_name` = \'' . $this->dbi->escapeString((string)$table) . '\''; - $row = $GLOBALS['dbi']->fetchSingleRow( + $row = $this->dbi->fetchSingleRow( $disp_query, 'ASSOC', DatabaseInterface::CONNECT_CONTROL @@ -903,10 +911,10 @@ class Relation /** * Pick first char field */ - $columns = $GLOBALS['dbi']->getColumnsFull($db, $table); + $columns = $this->dbi->getColumnsFull($db, $table); if ($columns) { foreach ($columns as $column) { - if ($GLOBALS['dbi']->types->getTypeClass($column['DATA_TYPE']) == 'CHAR') { + if ($this->dbi->types->getTypeClass($column['DATA_TYPE']) == 'CHAR') { return $column['COLUMN_NAME']; } } @@ -930,7 +938,7 @@ class Relation if ($table != '') { // MySQL native column comments - $columns = $GLOBALS['dbi']->getColumns($db, $table, null, true); + $columns = $this->dbi->getColumns($db, $table, null, true); if ($columns) { foreach ($columns as $column) { if (! empty($column['Comment'])) { @@ -966,7 +974,7 @@ class Relation FROM " . Util::backquote($cfgRelation['db']) . "." . Util::backquote($cfgRelation['column_info']) . " - WHERE db_name = '" . $GLOBALS['dbi']->escapeString($db) . "' + WHERE db_name = '" . $this->dbi->escapeString($db) . "' AND table_name = '' AND column_name = '(db_comment)'"; $com_rs = $this->queryAsControlUser( @@ -975,11 +983,11 @@ class Relation DatabaseInterface::QUERY_STORE ); - if ($com_rs && $GLOBALS['dbi']->numRows($com_rs) > 0) { - $row = $GLOBALS['dbi']->fetchAssoc($com_rs); + if ($com_rs && $this->dbi->numRows($com_rs) > 0) { + $row = $this->dbi->fetchAssoc($com_rs); $comment = $row['comment']; } - $GLOBALS['dbi']->freeResult($com_rs); + $this->dbi->freeResult($com_rs); } return $comment; @@ -1011,12 +1019,12 @@ class Relation DatabaseInterface::QUERY_STORE ); - if ($com_rs && $GLOBALS['dbi']->numRows($com_rs) > 0) { - while ($row = $GLOBALS['dbi']->fetchAssoc($com_rs)) { + if ($com_rs && $this->dbi->numRows($com_rs) > 0) { + while ($row = $this->dbi->fetchAssoc($com_rs)) { $comments[$row['db_name']] = $row['comment']; } } - $GLOBALS['dbi']->freeResult($com_rs); + $this->dbi->freeResult($com_rs); } return $comments; @@ -1046,17 +1054,17 @@ class Relation . Util::backquote($cfgRelation['column_info']) . ' (`db_name`, `table_name`, `column_name`, `comment`)' . ' VALUES (\'' - . $GLOBALS['dbi']->escapeString($db) + . $this->dbi->escapeString($db) . "', '', '(db_comment)', '" - . $GLOBALS['dbi']->escapeString($comment) + . $this->dbi->escapeString($comment) . "') " . ' ON DUPLICATE KEY UPDATE ' - . "`comment` = '" . $GLOBALS['dbi']->escapeString($comment) . "'"; + . "`comment` = '" . $this->dbi->escapeString($comment) . "'"; } else { $upd_query = 'DELETE FROM ' . Util::backquote($cfgRelation['db']) . '.' . Util::backquote($cfgRelation['column_info']) - . ' WHERE `db_name` = \'' . $GLOBALS['dbi']->escapeString($db) + . ' WHERE `db_name` = \'' . $this->dbi->escapeString($db) . '\' AND `table_name` = \'\' AND `column_name` = \'(db_comment)\''; @@ -1118,11 +1126,11 @@ class Relation `timevalue`, `sqlquery`) VALUES - (\'' . $GLOBALS['dbi']->escapeString($username) . '\', - \'' . $GLOBALS['dbi']->escapeString($db) . '\', - \'' . $GLOBALS['dbi']->escapeString($table) . '\', + (\'' . $this->dbi->escapeString($username) . '\', + \'' . $this->dbi->escapeString($db) . '\', + \'' . $this->dbi->escapeString($table) . '\', NOW(), - \'' . $GLOBALS['dbi']->escapeString($sqlquery) . '\')' + \'' . $this->dbi->escapeString($sqlquery) . '\')' ); $this->purgeHistory($username); @@ -1163,10 +1171,10 @@ class Relation `timevalue` FROM ' . Util::backquote($cfgRelation['db']) . '.' . Util::backquote($cfgRelation['history']) . ' - WHERE `username` = \'' . $GLOBALS['dbi']->escapeString($username) . '\' + WHERE `username` = \'' . $this->dbi->escapeString($username) . '\' ORDER BY `id` DESC'; - return $GLOBALS['dbi']->fetchResult( + return $this->dbi->fetchResult( $hist_query, null, null, @@ -1201,11 +1209,11 @@ class Relation SELECT `timevalue` FROM ' . Util::backquote($cfgRelation['db']) . '.' . Util::backquote($cfgRelation['history']) . ' - WHERE `username` = \'' . $GLOBALS['dbi']->escapeString($username) . '\' + WHERE `username` = \'' . $this->dbi->escapeString($username) . '\' ORDER BY `timevalue` DESC LIMIT ' . $GLOBALS['cfg']['QueryHistoryMax'] . ', 1'; - if ($max_time = $GLOBALS['dbi']->fetchValue( + if ($max_time = $this->dbi->fetchValue( $search_query, 0, 0, @@ -1215,7 +1223,7 @@ class Relation 'DELETE FROM ' . Util::backquote($cfgRelation['db']) . '.' . Util::backquote($cfgRelation['history']) . ' - WHERE `username` = \'' . $GLOBALS['dbi']->escapeString($username) + WHERE `username` = \'' . $this->dbi->escapeString($username) . '\' AND `timevalue` <= \'' . $max_time . '\'' ); @@ -1457,7 +1465,7 @@ class Relation // Check if table has more rows than specified by // $GLOBALS['cfg']['ForeignKeyMaxLimit'] - $moreThanLimit = $GLOBALS['dbi']->getTable($foreign_db, $foreign_table) + $moreThanLimit = $this->dbi->getTable($foreign_db, $foreign_table) ->checkIfMinRecordsExist($GLOBALS['cfg']['ForeignKeyMaxLimit']); if ($override_total == true @@ -1476,12 +1484,12 @@ class Relation . '.' . Util::backquote($foreign_table); $f_query_filter = empty($foreign_filter) ? '' : ' WHERE ' . Util::backquote($foreign_field) - . ' LIKE "%' . $GLOBALS['dbi']->escapeString($foreign_filter) . '%"' + . ' LIKE "%' . $this->dbi->escapeString($foreign_filter) . '%"' . ( ($foreign_display == false) ? '' : ' OR ' . Util::backquote($foreign_display) - . ' LIKE "%' . $GLOBALS['dbi']->escapeString($foreign_filter) + . ' LIKE "%' . $this->dbi->escapeString($foreign_filter) . '%"' ); $f_query_order = ($foreign_display == false) ? '' : ' ORDER BY ' @@ -1491,7 +1499,7 @@ class Relation $f_query_limit = ! empty($foreign_limit) ? ($foreign_limit) : ''; if (!empty($foreign_filter)) { - $the_total = $GLOBALS['dbi']->fetchValue( + $the_total = $this->dbi->fetchValue( 'SELECT COUNT(*)' . $f_query_from . $f_query_filter ); if ($the_total === false) { @@ -1499,20 +1507,20 @@ class Relation } } - $disp = $GLOBALS['dbi']->tryQuery( + $disp = $this->dbi->tryQuery( $f_query_main . $f_query_from . $f_query_filter . $f_query_order . $f_query_limit ); - if ($disp && $GLOBALS['dbi']->numRows($disp) > 0) { + if ($disp && $this->dbi->numRows($disp) > 0) { // If a resultset has been created, pre-cache it in the $disp_row // array. This helps us from not needing to use mysql_data_seek by // accessing a pre-cached PHP array. Usually those resultsets are // not that big, so a performance hit should not be expected. $disp_row = []; - while ($single_disp_row = @$GLOBALS['dbi']->fetchAssoc($disp)) { + while ($single_disp_row = @$this->dbi->fetchAssoc($disp)) { $disp_row[] = $single_disp_row; } - @$GLOBALS['dbi']->freeResult($disp); + @$this->dbi->freeResult($disp); } else { // Either no data in the foreign table or // user does not have select permission to foreign table/field @@ -1527,7 +1535,7 @@ class Relation } while (false); if ($get_total) { - $the_total = $GLOBALS['dbi']->getTable($foreign_db, $foreign_table) + $the_total = $this->dbi->getTable($foreign_db, $foreign_table) ->countRecords(true); } @@ -1563,14 +1571,14 @@ class Relation $table_query = 'UPDATE ' . Util::backquote($cfgRelation['db']) . '.' . Util::backquote($cfgRelation['table_info']) - . ' SET display_field = \'' . $GLOBALS['dbi']->escapeString( + . ' SET display_field = \'' . $this->dbi->escapeString( $new_name ) . '\'' - . ' WHERE db_name = \'' . $GLOBALS['dbi']->escapeString($db) + . ' WHERE db_name = \'' . $this->dbi->escapeString($db) . '\'' - . ' AND table_name = \'' . $GLOBALS['dbi']->escapeString($table) + . ' AND table_name = \'' . $this->dbi->escapeString($table) . '\'' - . ' AND display_field = \'' . $GLOBALS['dbi']->escapeString($field) + . ' AND display_field = \'' . $this->dbi->escapeString($field) . '\''; $this->queryAsControlUser($table_query); } @@ -1579,28 +1587,28 @@ class Relation $table_query = 'UPDATE ' . Util::backquote($cfgRelation['db']) . '.' . Util::backquote($cfgRelation['relation']) - . ' SET master_field = \'' . $GLOBALS['dbi']->escapeString( + . ' SET master_field = \'' . $this->dbi->escapeString( $new_name ) . '\'' - . ' WHERE master_db = \'' . $GLOBALS['dbi']->escapeString($db) + . ' WHERE master_db = \'' . $this->dbi->escapeString($db) . '\'' - . ' AND master_table = \'' . $GLOBALS['dbi']->escapeString($table) + . ' AND master_table = \'' . $this->dbi->escapeString($table) . '\'' - . ' AND master_field = \'' . $GLOBALS['dbi']->escapeString($field) + . ' AND master_field = \'' . $this->dbi->escapeString($field) . '\''; $this->queryAsControlUser($table_query); $table_query = 'UPDATE ' . Util::backquote($cfgRelation['db']) . '.' . Util::backquote($cfgRelation['relation']) - . ' SET foreign_field = \'' . $GLOBALS['dbi']->escapeString( + . ' SET foreign_field = \'' . $this->dbi->escapeString( $new_name ) . '\'' - . ' WHERE foreign_db = \'' . $GLOBALS['dbi']->escapeString($db) + . ' WHERE foreign_db = \'' . $this->dbi->escapeString($db) . '\'' - . ' AND foreign_table = \'' . $GLOBALS['dbi']->escapeString($table) + . ' AND foreign_table = \'' . $this->dbi->escapeString($table) . '\'' - . ' AND foreign_field = \'' . $GLOBALS['dbi']->escapeString($field) + . ' AND foreign_field = \'' . $this->dbi->escapeString($field) . '\''; $this->queryAsControlUser($table_query); } @@ -1633,14 +1641,14 @@ class Relation . Util::backquote($GLOBALS['cfgRelation']['db']) . '.' . Util::backquote($GLOBALS['cfgRelation'][$table]) . ' SET ' - . $db_field . ' = \'' . $GLOBALS['dbi']->escapeString($target_db) + . $db_field . ' = \'' . $this->dbi->escapeString($target_db) . '\', ' - . $table_field . ' = \'' . $GLOBALS['dbi']->escapeString($target_table) + . $table_field . ' = \'' . $this->dbi->escapeString($target_table) . '\'' . ' WHERE ' - . $db_field . ' = \'' . $GLOBALS['dbi']->escapeString($source_db) . '\'' + . $db_field . ' = \'' . $this->dbi->escapeString($source_db) . '\'' . ' AND ' - . $table_field . ' = \'' . $GLOBALS['dbi']->escapeString($source_table) + . $table_field . ' = \'' . $this->dbi->escapeString($source_table) . '\''; $this->queryAsControlUser($query); } @@ -1728,8 +1736,8 @@ class Relation $remove_query = "DELETE FROM " . Util::backquote($GLOBALS['cfgRelation']['db']) . "." . Util::backquote($GLOBALS['cfgRelation']['table_coords']) - . " WHERE db_name = '" . $GLOBALS['dbi']->escapeString($source_db) . "'" - . " AND table_name = '" . $GLOBALS['dbi']->escapeString($source_table) + . " WHERE db_name = '" . $this->dbi->escapeString($source_db) . "'" + . " AND table_name = '" . $this->dbi->escapeString($source_table) . "'"; $this->queryAsControlUser($remove_query); } @@ -1765,13 +1773,13 @@ class Relation . Util::backquote( $GLOBALS['cfgRelation']['navigationhiding'] ) - . " SET db_name = '" . $GLOBALS['dbi']->escapeString($target_db) + . " SET db_name = '" . $this->dbi->escapeString($target_db) . "'," - . " item_name = '" . $GLOBALS['dbi']->escapeString($target_table) + . " item_name = '" . $this->dbi->escapeString($target_table) . "'" - . " WHERE db_name = '" . $GLOBALS['dbi']->escapeString($source_db) + . " WHERE db_name = '" . $this->dbi->escapeString($source_db) . "'" - . " AND item_name = '" . $GLOBALS['dbi']->escapeString($source_table) + . " AND item_name = '" . $this->dbi->escapeString($source_table) . "'" . " AND item_type = 'table'"; $this->queryAsControlUser($query); @@ -1797,11 +1805,11 @@ class Relation . Util::backquote($cfgRelation['pdf_pages']) . ' (db_name, page_descr)' . ' VALUES (\'' - . $GLOBALS['dbi']->escapeString($db) . '\', \'' - . $GLOBALS['dbi']->escapeString($newpage) . '\')'; + . $this->dbi->escapeString($db) . '\', \'' + . $this->dbi->escapeString($newpage) . '\')'; $this->queryAsControlUser($ins_query, false); - return $GLOBALS['dbi']->insertId(DatabaseInterface::CONNECT_CONTROL); + return $this->dbi->insertId(DatabaseInterface::CONNECT_CONTROL); } /** @@ -1822,15 +1830,15 @@ class Relation . " `table_schema`, `referenced_column_name`" . " FROM `information_schema`.`key_column_usage`" . " WHERE `referenced_table_name` = '" - . $GLOBALS['dbi']->escapeString($table) . "'" + . $this->dbi->escapeString($table) . "'" . " AND `referenced_table_schema` = '" - . $GLOBALS['dbi']->escapeString($db) . "'"; + . $this->dbi->escapeString($db) . "'"; if ($column) { $rel_query .= " AND `referenced_column_name` = '" - . $GLOBALS['dbi']->escapeString($column) . "'"; + . $this->dbi->escapeString($column) . "'"; } - $child_references = $GLOBALS['dbi']->fetchResult( + $child_references = $this->dbi->fetchResult( $rel_query, ['referenced_column_name', null] ); @@ -1982,8 +1990,8 @@ class Relation */ public function createPmaDatabase() { - $GLOBALS['dbi']->tryQuery("CREATE DATABASE IF NOT EXISTS `phpmyadmin`"); - if ($error = $GLOBALS['dbi']->getError()) { + $this->dbi->tryQuery("CREATE DATABASE IF NOT EXISTS `phpmyadmin`"); + if ($error = $this->dbi->getError()) { if ($GLOBALS['errno'] == 1044) { $GLOBALS['message'] = __( 'You do not have necessary privileges to create a database named' @@ -2030,7 +2038,7 @@ class Relation 'pma__export_templates' => 'export_templates', ]; - $existingTables = $GLOBALS['dbi']->getTables($db, DatabaseInterface::CONNECT_CONTROL); + $existingTables = $this->dbi->getTables($db, DatabaseInterface::CONNECT_CONTROL); $createQueries = null; $foundOne = false; @@ -2039,10 +2047,10 @@ class Relation if ($create) { if ($createQueries == null) { // first create $createQueries = $this->getDefaultPmaTableNames(); - $GLOBALS['dbi']->selectDb($db); + $this->dbi->selectDb($db); } - $GLOBALS['dbi']->tryQuery($createQueries[$table]); - if ($error = $GLOBALS['dbi']->getError()) { + $this->dbi->tryQuery($createQueries[$table]); + if ($error = $this->dbi->getError()) { $GLOBALS['message'] = $error; return; } @@ -2200,12 +2208,12 @@ class Relation public function getTables($foreignDb, $tblStorageEngine) { $tables = []; - $tablesRows = $GLOBALS['dbi']->query( + $tablesRows = $this->dbi->query( 'SHOW TABLE STATUS FROM ' . Util::backquote($foreignDb), DatabaseInterface::CONNECT_USER, DatabaseInterface::QUERY_STORE ); - while ($row = $GLOBALS['dbi']->fetchRow($tablesRows)) { + while ($row = $this->dbi->fetchRow($tablesRows)) { if (isset($row[1]) && mb_strtoupper($row[1]) == $tblStorageEngine) { $tables[] = $row[0]; } diff --git a/libraries/classes/RelationCleanup.php b/libraries/classes/RelationCleanup.php index 1cbd4b8726..bf02acdf8c 100644 --- a/libraries/classes/RelationCleanup.php +++ b/libraries/classes/RelationCleanup.php @@ -30,7 +30,7 @@ class RelationCleanup */ public static function column($db, $table, $column) { - $relation = new Relation(); + $relation = new Relation($GLOBALS['dbi']); $cfgRelation = $relation->getRelationsParam(); if ($cfgRelation['commwork']) { @@ -92,7 +92,7 @@ class RelationCleanup */ public static function table($db, $table) { - $relation = new Relation(); + $relation = new Relation($GLOBALS['dbi']); $cfgRelation = $relation->getRelationsParam(); if ($cfgRelation['commwork']) { @@ -178,7 +178,7 @@ class RelationCleanup */ public static function database($db) { - $relation = new Relation(); + $relation = new Relation($GLOBALS['dbi']); $cfgRelation = $relation->getRelationsParam(); if ($cfgRelation['commwork']) { @@ -277,7 +277,7 @@ class RelationCleanup */ public static function user($username) { - $relation = new Relation(); + $relation = new Relation($GLOBALS['dbi']); $cfgRelation = $relation->getRelationsParam(); if ($cfgRelation['bookmarkwork']) { diff --git a/libraries/classes/SavedSearches.php b/libraries/classes/SavedSearches.php index 32cf606f5e..f06e1659d2 100644 --- a/libraries/classes/SavedSearches.php +++ b/libraries/classes/SavedSearches.php @@ -70,7 +70,7 @@ class SavedSearches public function __construct(array $config) { $this->setConfig($config); - $this->relation = new Relation(); + $this->relation = new Relation($GLOBALS['dbi']); } /** diff --git a/libraries/classes/Server/Privileges.php b/libraries/classes/Server/Privileges.php index 665107431e..a452352ff2 100644 --- a/libraries/classes/Server/Privileges.php +++ b/libraries/classes/Server/Privileges.php @@ -544,7 +544,7 @@ class Privileges */ public function getHtmlToChooseUserGroup($username) { - $relation = new Relation(); + $relation = new Relation($GLOBALS['dbi']); $cfgRelation = $relation->getRelationsParam(); $groupTable = Util::backquote($cfgRelation['db']) . "." . Util::backquote($cfgRelation['usergroups']); @@ -591,7 +591,7 @@ class Privileges public function setUserGroup($username, $userGroup) { $userGroup = is_null($userGroup) ? '' : $userGroup; - $relation = new Relation(); + $relation = new Relation($GLOBALS['dbi']); $cfgRelation = $relation->getRelationsParam(); if (empty($cfgRelation['db']) || empty($cfgRelation['users']) || empty($cfgRelation['usergroups'])) { return; @@ -2944,7 +2944,7 @@ class Privileges */ public function getUserGroupCount() { - $relation = new Relation(); + $relation = new Relation($GLOBALS['dbi']); $cfgRelation = $relation->getRelationsParam(); $user_group_table = Util::backquote($cfgRelation['db']) . '.' . Util::backquote($cfgRelation['usergroups']); @@ -2968,7 +2968,7 @@ class Privileges */ public function getUserGroupForUser($username) { - $relation = new Relation(); + $relation = new Relation($GLOBALS['dbi']); $cfgRelation = $relation->getRelationsParam(); if (empty($cfgRelation['db']) @@ -3013,7 +3013,7 @@ class Privileges $hostname, $username ) { - $relation = new Relation(); + $relation = new Relation($GLOBALS['dbi']); if (isset($GLOBALS['dbname'])) { //if (preg_match('/\\\\(?:_|%)/i', $dbname)) { if (preg_match('/(?getRelationsParam(); $user_group_count = 0; if ($cfgRelation['menuswork']) { diff --git a/libraries/classes/Server/UserGroups.php b/libraries/classes/Server/UserGroups.php index 94ea51a8eb..34a6c71907 100644 --- a/libraries/classes/Server/UserGroups.php +++ b/libraries/classes/Server/UserGroups.php @@ -29,7 +29,7 @@ class UserGroups */ public static function getHtmlForListingUsersofAGroup($userGroup) { - $relation = new Relation(); + $relation = new Relation($GLOBALS['dbi']); $html_output = '