From d9eebc2ae067b7d17d2c0e115555ed898af633a4 Mon Sep 17 00:00:00 2001 From: Sebastian Mendel Date: Tue, 16 Oct 2007 14:02:16 +0000 Subject: [PATCH] removed closing of db connection, closing database connection is only required if script runs longer than database connection is needed --- browse_foreigners.php | 12 ---- db_qbe.php | 97 +++----------------------------- libraries/dbi/mysql.dbi.lib.php | 12 ---- libraries/dbi/mysqli.dbi.lib.php | 20 ------- libraries/footer.inc.php | 11 ---- libraries/relation.lib.php | 54 +++++++++++++++++- navigation.php | 12 ---- querywindow.php | 12 ---- transformation_wrapper.php | 10 ---- 9 files changed, 62 insertions(+), 178 deletions(-) diff --git a/browse_foreigners.php b/browse_foreigners.php index 7c33b34f4..65010670c 100644 --- a/browse_foreigners.php +++ b/browse_foreigners.php @@ -287,15 +287,3 @@ if (is_array($foreignData['disp_row'])) { - - diff --git a/db_qbe.php b/db_qbe.php index 12e26769f..8b44123a5 100644 --- a/db_qbe.php +++ b/db_qbe.php @@ -628,7 +628,7 @@ echo PMA_generate_common_hidden_inputs($url_params); $val) { +foreach ($tbl_names as $key => $val) { $strTableListOptions .= ' '; $strTableListOptions .= '' . "\n"; @@ -694,7 +694,7 @@ if (isset($Field) && count($Field) > 0) { $fromclause = ''; // We only start this if we have fields, otherwise it would be dumb - foreach ($Field AS $value) { + foreach ($Field as $value) { $parts = explode('.', $value); if (!empty($parts[0]) && !empty($parts[1])) { $tab_raw = urldecode($parts[0]); @@ -746,7 +746,7 @@ if (isset($Field) && count($Field) > 0) { // the last db selected is not always the one where we need to work) PMA_DBI_select_db($db); - foreach ($tab_all AS $tab) { + foreach ($tab_all as $tab) { $ind_rs = PMA_DBI_query('SHOW INDEX FROM ' . PMA_backquote($tab) . ';'); while ($ind = PMA_DBI_fetch_assoc($ind_rs)) { $col1 = $tab . '.' . $ind['Column_name']; @@ -787,7 +787,7 @@ if (isset($Field) && count($Field) > 0) { // (that would mean that they were also found in the whereclauses // which would be great). if yes, we take only those if ($needsort == 1) { - foreach ($col_cand AS $col => $is_where) { + foreach ($col_cand as $col => $is_where) { $tab = explode('.', $col); $tab = $tab[0]; if ($is_where == 'Y') { @@ -813,7 +813,7 @@ if (isset($Field) && count($Field) > 0) { if (count($col_cand) > 1) { // Of course we only want to check each table once $checked_tables = $col_cand; - foreach ($col_cand AS $tab) { + foreach ($col_cand as $tab) { if ($checked_tables[$tab] != 1) { $tsize[$tab] = PMA_Table::countRecords($db, $tab, true, false); $checked_tables[$tab] = 1; @@ -829,86 +829,7 @@ if (isset($Field) && count($Field) > 0) { } } // end if (exactly one where clause) - /** - * Removes unwanted entries from an array (PHP3 compliant) - * - * @param array the array to work with - * @param array the list of keys to remove - * - * @return array the cleaned up array - * - * @access private - */ - function PMA_arrayShort($array, $key) - { - foreach ($array AS $k => $v) { - if ($k != $key) { - $reta[$k] = $v; - } - } - if (!isset($reta)) { - $reta = array(); - } - - return $reta; - } // end of the "PMA_arrayShort()" function - - - /** - * Finds all related tables - * - * @param string wether to go from master to foreign or vice versa - * - * @return boolean always TRUE - * - * @global array the list of tables that we still couldn't connect - * @global array the list of allready connected tables - * @global string the current databse name - * @global string the super user connection id - * @global array the list of relation settings - * - * @access private - */ - function PMA_getRelatives($from) { - global $tab_left, $tab_know, $fromclause; - global $controllink, $db, $cfgRelation; - - if ($from == 'master') { - $to = 'foreign'; - } else { - $to = 'master'; - } - $in_know = '(\'' . implode('\', \'', $tab_know) . '\')'; - $in_left = '(\'' . implode('\', \'', $tab_left) . '\')'; - - $rel_query = 'SELECT *' - . ' FROM ' . PMA_backquote($cfgRelation['relation']) - . ' WHERE ' . $from . '_db = \'' . PMA_sqlAddslashes($db) . '\'' - . ' AND ' . $to . '_db = \'' . PMA_sqlAddslashes($db) . '\'' - . ' AND ' . $from . '_table IN ' . $in_know - . ' AND ' . $to . '_table IN ' . $in_left; - PMA_DBI_select_db($cfgRelation['db'], $controllink); - $relations = @PMA_DBI_query($rel_query, $controllink); - PMA_DBI_select_db($db, $controllink); - while ($row = PMA_DBI_fetch_assoc($relations)) { - $found_table = $row[$to . '_table']; - if (isset($tab_left[$found_table])) { - $fromclause .= "\n" . ' LEFT JOIN ' - . PMA_backquote($row[$to . '_table']) . ' ON ' - . PMA_backquote($row[$from . '_table']) . '.' - . PMA_backquote($row[$from . '_field']) . ' = ' - . PMA_backquote($row[$to . '_table']) . '.' - . PMA_backquote($row[$to . '_field']) . ' '; - $tab_know[$found_table] = $found_table; - $tab_left = PMA_arrayShort($tab_left, $found_table); - } - } // end while - - return TRUE; - } // end of the "PMA_getRelatives()" function - - - $tab_left = PMA_arrayShort($tab_all, $master); + unset($tab_all[$master]); $tab_know[$master] = $master; $run = 0; @@ -922,9 +843,9 @@ if (isset($Field) && count($Field) > 0) { $run++; if ($run > 5) { - foreach ($tab_left AS $tab) { - $emerg .= ', ' . PMA_backquote($tab); - $tab_left = PMA_arrayShort($tab_left, $tab); + foreach ($tab_left as $tab) { + $emerg .= ', ' . PMA_backquote($tab); + unset($tab_left[$tab]); } } } // end while diff --git a/libraries/dbi/mysql.dbi.lib.php b/libraries/dbi/mysql.dbi.lib.php index ea0a4a69f..4c18f778b 100644 --- a/libraries/dbi/mysql.dbi.lib.php +++ b/libraries/dbi/mysql.dbi.lib.php @@ -284,18 +284,6 @@ function PMA_DBI_getError($link = null) return $error; } -function PMA_DBI_close($link = null) -{ - if (empty($link)) { - if (isset($GLOBALS['userlink'])) { - $link = $GLOBALS['userlink']; - } else { - return false; - } - } - return @mysql_close($link); -} - function PMA_DBI_num_rows($result) { if (!is_bool($result)) { diff --git a/libraries/dbi/mysqli.dbi.lib.php b/libraries/dbi/mysqli.dbi.lib.php index 1cf6a03b4..45e9fce47 100644 --- a/libraries/dbi/mysqli.dbi.lib.php +++ b/libraries/dbi/mysqli.dbi.lib.php @@ -369,26 +369,6 @@ function PMA_DBI_getError($link = null) return $error; } -/** - * closes given database $link or $GLOBALS['userlink'] - * - * @uses $GLOBALS['userlink'] - * @uses mysqli_close() - * @param object mysqli $link the mysqli object - * @return boolean treu or false - */ -function PMA_DBI_close($link = null) -{ - if (empty($link)) { - if (isset($GLOBALS['userlink'])) { - $link = $GLOBALS['userlink']; - } else { - return false; - } - } - return @mysqli_close($link); -} - /** * * @param object mysqli result $result diff --git a/libraries/footer.inc.php b/libraries/footer.inc.php index 3af680ce3..e0ff3e7a8 100644 --- a/libraries/footer.inc.php +++ b/libraries/footer.inc.php @@ -39,7 +39,6 @@ * @uses PMA_escapeJsString() * @uses PMA_getenv() * @uses PMA_generate_common_url() - * @uses PMA_DBI_close() * @uses basename() * @uses file_exists() * @version $Id$ @@ -165,16 +164,6 @@ if (PMA_getenv('SCRIPT_NAME') && empty($_POST) && !$GLOBALS['checked_special']) echo '' . "\n"; } -/** - * Close database connections - */ -if (! empty($GLOBALS['controllink'])) { - @PMA_DBI_close($GLOBALS['controllink']); -} -if (! empty($GLOBALS['userlink'])) { - @PMA_DBI_close($GLOBALS['userlink']); -} - // Include possible custom footers if (file_exists('./config.footer.inc.php')) { require './config.footer.inc.php'; diff --git a/libraries/relation.lib.php b/libraries/relation.lib.php index 2ea880ad0..a391f3a21 100644 --- a/libraries/relation.lib.php +++ b/libraries/relation.lib.php @@ -107,7 +107,7 @@ function PMA_printRelationsParamDiagnostic($cfgRelation) } echo '' . "\n"; - + PMA_printDiagMessageForParameter('pmadb', $GLOBALS['cfg']['Server']['pmadb'], $messages, 'pmadb'); PMA_printDiagMessageForParameter('relation', isset($cfgRelation['relation']), $messages, 'relation'); @@ -993,4 +993,56 @@ function PMA_getForeignData($foreigners, $field, $override_total, $foreign_filte return $foreignData; } // end of 'PMA_getForeignData()' function +/** + * Finds all related tables + * + * @param string wether to go from master to foreign or vice versa + * + * @return boolean always TRUE + * + * @global array the list of tables that we still couldn't connect + * @global array the list of allready connected tables + * @global string the current databse name + * @global string the super user connection id + * @global array the list of relation settings + * + * @access private + */ +function PMA_getRelatives($from) { + global $tab_left, $tab_know, $fromclause; + global $db, $cfgRelation; + + if ($from == 'master') { + $to = 'foreign'; + } else { + $to = 'master'; + } + $in_know = '(\'' . implode('\', \'', $tab_know) . '\')'; + $in_left = '(\'' . implode('\', \'', $tab_left) . '\')'; + + $rel_query = 'SELECT *' + . ' FROM ' . PMA_backquote($cfgRelation['db']) . '.' . PMA_backquote($cfgRelation['relation']) + . ' WHERE ' . $from . '_db = \'' . PMA_sqlAddslashes($db) . '\'' + . ' AND ' . $to . '_db = \'' . PMA_sqlAddslashes($db) . '\'' + . ' AND ' . $from . '_table IN ' . $in_know + . ' AND ' . $to . '_table IN ' . $in_left; + $relations = @PMA_DBI_query($rel_query, $GLOBALS['controllink']); + while ($row = PMA_DBI_fetch_assoc($relations)) { + $found_table = $row[$to . '_table']; + if (isset($tab_left[$found_table])) { + $fromclause + .= "\n" . ' LEFT JOIN ' + . PMA_backquote($db) . '.' . PMA_backquote($row[$to . '_table']) . ' ON ' + . PMA_backquote($row[$from . '_table']) . '.' + . PMA_backquote($row[$from . '_field']) . ' = ' + . PMA_backquote($row[$to . '_table']) . '.' + . PMA_backquote($row[$to . '_field']) . ' '; + $tab_know[$found_table] = $found_table; + unset($tab_left[$found_table]); + } + } // end while + + return TRUE; +} // end of the "PMA_getRelatives()" function + ?> diff --git a/navigation.php b/navigation.php index d533979ec..d04496a71 100644 --- a/navigation.php +++ b/navigation.php @@ -52,23 +52,11 @@ require_once './libraries/common.inc.php'; * * @uses $GLOBALS['controllink'] to close it * @uses $GLOBALS['userlink'] to close it - * @uses PMA_DBI_close() * @access private only to be used in navigation.php */ function PMA_exitNavigationFrame() { echo ''; - - /** - * Close MySQL connections - */ - if (isset($GLOBALS['controllink']) && $GLOBALS['controllink']) { - @PMA_DBI_close($GLOBALS['controllink']); - } - if (isset($GLOBALS['userlink']) && $GLOBALS['userlink']) { - @PMA_DBI_close($GLOBALS['userlink']); - } - exit; } diff --git a/querywindow.php b/querywindow.php index 7305bac6a..08af2dd44 100644 --- a/querywindow.php +++ b/querywindow.php @@ -264,15 +264,3 @@ if (! empty($_sql_history) - - diff --git a/transformation_wrapper.php b/transformation_wrapper.php index a2f669f49..1871baf7c 100644 --- a/transformation_wrapper.php +++ b/transformation_wrapper.php @@ -114,14 +114,4 @@ if (!isset($resize)) { ImageDestroy($srcImage); ImageDestroy($destImage); } - -/** - * Close MySql non-persistent connections - */ -if (isset($GLOBALS['controllink']) && $GLOBALS['controllink']) { - @PMA_DBI_close($GLOBALS['controllink']); -} -if (isset($GLOBALS['userlink']) && $GLOBALS['userlink']) { - @PMA_DBI_close($GLOBALS['userlink']); -} ?>