removed closing of db connection, closing database connection is only required if script runs longer than database connection is needed

This commit is contained in:
Sebastian Mendel
2007-10-16 14:02:16 +00:00
parent 46b110828b
commit d9eebc2ae0
9 changed files with 62 additions and 178 deletions

View File

@@ -287,15 +287,3 @@ if (is_array($foreignData['disp_row'])) {
</body>
</html>
<?php
/**
* Close MySql connections
*/
if (isset($controllink) && $controllink) {
@PMA_DBI_close($controllink);
}
if (isset($userlink) && $userlink) {
@PMA_DBI_close($userlink);
}
?>

View File

@@ -628,7 +628,7 @@ echo PMA_generate_common_hidden_inputs($url_params);
<?php
$strTableListOptions = '';
$numTableListOptions = 0;
foreach ($tbl_names AS $key => $val) {
foreach ($tbl_names as $key => $val) {
$strTableListOptions .= ' ';
$strTableListOptions .= '<option value="' . htmlspecialchars($key) . '"' . $val . '>'
. str_replace(' ', '&nbsp;', htmlspecialchars($key)) . '</option>' . "\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) {
foreach ($tab_left as $tab) {
$emerg .= ', ' . PMA_backquote($tab);
$tab_left = PMA_arrayShort($tab_left, $tab);
unset($tab_left[$tab]);
}
}
} // end while

View File

@@ -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)) {

View File

@@ -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

View File

@@ -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 '</div>' . "\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';

View File

@@ -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
?>

View File

@@ -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 '</body></html>';
/**
* 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;
}

View File

@@ -264,15 +264,3 @@ if (! empty($_sql_history)
</div>
</body>
</html>
<?php
/**
* Close MySql connections
*/
if (! empty($controllink)) {
PMA_DBI_close($controllink);
}
if (! empty($userlink)) {
PMA_DBI_close($userlink);
}
?>

View File

@@ -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']);
}
?>