diff --git a/ChangeLog b/ChangeLog index af3ca782d..230e7ed8c 100755 --- a/ChangeLog +++ b/ChangeLog @@ -19,6 +19,8 @@ $Source$ support-). * lang/czech-iso.inc.php3 & czech-win1250.inc.php3: updated thanks to Michal Cihar. + * tbl_properties.php3; db_details.php3; db_stats.php3; lib.inc.php3; + sql.php3: optimized a bit (mainly added some 'mysql_free_result'). 2001-09-05 Loïc Chapeaux * lib.inc.php3: diff --git a/db_details.php3 b/db_details.php3 index ef7c75622..c4b9000c0 100755 --- a/db_details.php3 +++ b/db_details.php3 @@ -52,8 +52,8 @@ if (mysql_error() != '') { if ($num_tables > 0 && MYSQL_INT_VERSION >= 32303) { // Special speedup for newer MySQL Versions (in 4.0 format changed) if ($cfgSkipLockedTables == TRUE && MYSQL_INT_VERSION >= 32330) { - $query = 'SHOW OPEN TABLES FROM ' . backquote($db); - $result = mysql_query($query); + $local_query = 'SHOW OPEN TABLES FROM ' . backquote($db); + $result = mysql_query($query) or mysql_die('', $local_query); // Blending out tables in use if ($result != FALSE && mysql_num_rows($result) > 0) { while ($tmp = mysql_fetch_array($result)) { @@ -65,13 +65,14 @@ if ($num_tables > 0 && MYSQL_INT_VERSION >= 32303) { mysql_free_result($result); if (isset($sot_cache)) { - $query = 'SHOW TABLES FROM ' . backquote($db); - $result = mysql_query($query); + $local_query = 'SHOW TABLES FROM ' . backquote($db); + $result = mysql_query($query) or mysql_die('', $local_query); if ($result != FALSE && mysql_num_rows($result) > 0) { while ($tmp = mysql_fetch_array($result)) { if (!isset($sot_cache[$tmp[0]])) { - $sts_result = mysql_query('SHOW TABLE STATUS FROM ' . backquote($db) . ' LIKE \'' . addslashes($tmp[0]) . '\''); - $sts_tmp = mysql_fetch_array($sts_result); + $local_query = 'SHOW TABLE STATUS FROM ' . backquote($db) . ' LIKE \'' . addslashes($tmp[0]) . '\''; + $sts_result = mysql_query($local_query) or mysql_die('', $local_query); + $sts_tmp = mysql_fetch_array($sts_result) or mysql_die('', $local_query); $tbl_cache[] = $sts_tmp; } else { // table in use $tbl_cache[] = array('Name' => $tmp[0]); @@ -84,7 +85,8 @@ if ($num_tables > 0 && MYSQL_INT_VERSION >= 32303) { } } if (!isset($sot_ready)) { - $result = mysql_query('SHOW TABLE STATUS FROM ' . backquote($db)); + $local_query = 'SHOW TABLE STATUS FROM ' . backquote($db); + $result = mysql_query($local_query) or mysql_die('', $local_query); if ($result != FALSE && mysql_num_rows($result) > 0) { while ($sts_tmp = mysql_fetch_array($result)) { $tbl_cache[] = $sts_tmp; @@ -338,7 +340,7 @@ else { @@ -468,8 +470,9 @@ if ($num_tables > 0) { 1) { $colspan = ' colspan="2"'; echo "\n"; @@ -488,7 +491,9 @@ if ($num_tables > 0) { diff --git a/db_stats.php3 b/db_stats.php3 index 0449af6ed..61b3492cf 100644 --- a/db_stats.php3 +++ b/db_stats.php3 @@ -72,7 +72,8 @@ if ($server > 0) { } else { $true_dblist[$a_db->Database] = ''; } - } + } // end while + mysql_free_result($dbs); if ($num_dbs && empty($true_dblist)) { $dblist = array(); } else if ($num_dbs) { @@ -211,6 +212,7 @@ if ($num_dbs > 0) { // Number of tables $dbs_array[$db][0] = @mysql_numrows($tables); + mysql_free_result($tables); $total_array[0] += $dbs_array[$db][0]; // Size of data and indexes @@ -230,8 +232,10 @@ if ($num_dbs > 0) { $total_array[1] += $dbs_array[$db][1]; $total_array[2] += $dbs_array[$db][2]; $total_array[3] += $dbs_array[$db][3]; - } + } // end if + mysql_free_result($result); } // end for + mysql_close(); // Sorts the dbs arrays uksort($dbs_array, 'pmaDbCmp'); diff --git a/lib.inc.php3 b/lib.inc.php3 index bb9ec9d40..bfdb2b5eb 100755 --- a/lib.inc.php3 +++ b/lib.inc.php3 @@ -373,6 +373,7 @@ if (!defined('__LIB_INC__')){ // Seems to be a valid login... else { $row = mysql_fetch_array($rs); + mysql_free_result($rs); // Correction uva 19991215 // Previous code assumed database "mysql" admin table "db" // column "db" contains literal name of user database, and @@ -397,6 +398,7 @@ if (!defined('__LIB_INC__')){ while ($row = mysql_fetch_array($rs)) { $dblist[] = $row['Db']; } + mysql_free_result($rs); } } else { // Will use as associative array of the following 2 @@ -413,6 +415,7 @@ if (!defined('__LIB_INC__')){ while ($row = mysql_fetch_array($rs)) { $uva_mydbs[$row['Db']] = 1; } + mysql_free_result($rs); $uva_alldbs = mysql_list_dbs(); while ($uva_row = mysql_fetch_array($uva_alldbs)) { $uva_db = $uva_row[0]; @@ -432,6 +435,7 @@ if (!defined('__LIB_INC__')){ } // end while } // end if ... else .... } // end while + mysql_free_result($uva_alldbs); } // end else } // end if } // end else @@ -659,8 +663,9 @@ if (!defined('__LIB_INC__')){ */ function count_records($db, $table, $ret = FALSE) { - $result = mysql_query('select count(*) as num from ' . backquote($db) . '.' . backquote($table)); - $num = mysql_result($result,0,"num"); + $result = mysql_query('SELECT COUNT(*) AS num FROM ' . backquote($db) . '.' . backquote($table)); + $num = mysql_result($result, 0, 'num'); + mysql_free_result($result); if ($ret) { return $num; } else { @@ -996,6 +1001,7 @@ window.parent.frames['nav'].location.replace(''); $local_query = 'SELECT COUNT(*) AS total FROM ' . backquote($db) . '.' . backquote($table); $result = mysql_query($local_query) or mysql_die('', $local_query); $the_total = mysql_result($result, 0, 'total'); + mysql_free_result($result); } // 4. If navigation bar or sorting fields names urls should be @@ -1808,6 +1814,7 @@ window.parent.frames['nav'].location.replace(''); $tmpres = mysql_fetch_array($result); $schema_create .= str_replace("\n", $crlf, html_format($tmpres[1])); } + mysql_free_result($result); return $schema_create; } // end if MySQL >= 3.23.20 @@ -1829,6 +1836,7 @@ window.parent.frames['nav'].location.replace(''); } $schema_create .= ',' . $crlf; } // end while + mysql_free_result($result); $schema_create = ereg_replace(',' . $crlf . '$', '', $schema_create); $local_query = 'SHOW KEYS FROM ' . backquote($db) . '.' . backquote($table); @@ -1854,6 +1862,7 @@ window.parent.frames['nav'].location.replace(''); $index[$kname][] = html_format(backquote($row['Column_name'], $use_backquotes)); } } // end while + mysql_free_result($result); while (list($x, $columns) = @each($index)) { $schema_create .= ',' . $crlf; @@ -1984,6 +1993,7 @@ window.parent.frames['nav'].location.replace(''); $GLOBALS['tmp_buffer'] = ereg_replace(',([^,]*)$', ';\\1', $GLOBALS['tmp_buffer']); } } // end if ($result != FALSE) + mysql_free_result($result); return TRUE; } // end of the 'get_table_content_fast()' function @@ -2019,12 +2029,13 @@ window.parent.frames['nav'].location.replace(''); $result = mysql_query($local_query) or mysql_die('', $local_query); $i = 0; $isFirstRow = TRUE; + $fields_cnt = mysql_num_fields($result); while ($row = mysql_fetch_row($result)) { @set_time_limit(60); // HaRa $table_list = '('; - for ($j = 0; $j < mysql_num_fields($result); $j++) { + for ($j = 0; $j < $fields_cnt; $j++) { $table_list .= backquote(mysql_field_name($result, $j), $use_backquotes) . ', '; } @@ -2044,7 +2055,7 @@ window.parent.frames['nav'].location.replace(''); $isFirstRow = FALSE; } - for ($j = 0; $j < mysql_num_fields($result); $j++) { + for ($j = 0; $j < $fields_cnt; $j++) { if (!isset($row[$j])) { $schema_insert .= ' NULL,'; } else if ($row[$j] != '') { @@ -2073,6 +2084,7 @@ window.parent.frames['nav'].location.replace(''); $handler(trim($schema_insert)); ++$i; } // end while + mysql_free_result($result); // Replace last comma by a semi-column in extended inserts case if ($i > 0 && isset($GLOBALS['extended_ins'])) { @@ -2191,13 +2203,13 @@ window.parent.frames['nav'].location.replace(''); // Gets the data from the database $local_query = 'SELECT * FROM ' . backquote($db) . '.' . backquote($table) . $add_query; $result = mysql_query($local_query) or mysql_die('', $local_query); + $fields_cnt = mysql_num_fields($result); // Format the data $i = 0; while ($row = mysql_fetch_row($result)) { @set_time_limit(60); $schema_insert = ''; - $fields_cnt = mysql_num_fields($result); for ($j = 0; $j < $fields_cnt; $j++) { if (!isset($row[$j])) { $schema_insert .= 'NULL'; @@ -2221,6 +2233,7 @@ window.parent.frames['nav'].location.replace(''); $handler(trim($schema_insert)); ++$i; } // end while + mysql_free_result($result); return TRUE; } // end of the 'get_table_csv()' function diff --git a/sql.php3 b/sql.php3 index 6f1db6227..aeeb0d0df 100755 --- a/sql.php3 +++ b/sql.php3 @@ -198,6 +198,7 @@ else { } else { $num_rows = 0; } + mysql_free_result($OPresult); } // Executes the query @@ -232,6 +233,7 @@ else { if ($OPresult) { $unlim_num_rows = mysql_result($OPresult, 0, 'count'); } + mysql_free_result($OPresult); } else { $unlim_num_rows = 0; } @@ -301,6 +303,7 @@ else { $disp_mode = 'urdr11110'; } display_table($result, $disp_mode); + mysql_free_result($result); // Displays "Insert a new row" link if required if ($disp_mode[6] == '1') { diff --git a/tbl_properties.php3 b/tbl_properties.php3 index 375a8bd70..13ba31648 100755 --- a/tbl_properties.php3 +++ b/tbl_properties.php3 @@ -63,6 +63,8 @@ if (!empty($table)) { if (empty($table) || !@mysql_numrows($is_table)) { header('Location: ' . $cfgPmaAbsoluteUri . 'db_details.php3?lang=' . $lang . '&server=' . $server . '&db=' . urlencode($db) . '&reload=true'); exit(); +} else { + mysql_free_result($result); } @@ -118,6 +120,7 @@ if (MYSQL_INT_VERSION >= 32303) { $num_rows = mysql_result($result, 0, 'count'); $show_comment = ''; } +mysql_free_result($result); ?> 0 && $row['Key_name'] != $prev_key && $prev_seq == 1) { + unset($ret_keys[$i-1]['Seq_in_index']); + } + $prev_key = $row['Key_name']; + $prev_seq = $row['Seq_in_index']; + // Backups the list of primary keys if ($row['Key_name'] == 'PRIMARY') { $primary .= $row['Column_name'] . ', '; $pk_array[$row['Column_name']] = 1; } + $i++; } +// Unset the 'Seq_in_index' value if it's not a composite index - part 2 +if ($i > 0 && $row['Key_name'] != $prev_key && $prev_seq == 1) { + unset($ret_keys[$i-1]['Seq_in_index']); +} +mysql_free_result($result); + // 3. Get fields $local_query = 'SHOW FIELDS FROM ' . backquote($table); @@ -186,37 +206,23 @@ $result = mysql_query($local_query) or mysql_die('', $local_query); $fields_cnt = mysql_num_rows($result); + /** * Displays the table structure ('show table' works correct since 3.23.03) */ ?> - - - 1) { - ?>
- - 1) { - echo ' ' . "\n"; -} -?> + @@ -280,17 +286,9 @@ while ($row = mysql_fetch_array($result)) { echo "\n"; ?> - 1) { - ?> - > @@ -333,30 +331,31 @@ while ($row = mysql_fetch_array($result)) { 1) { - ?> +mysql_free_result($result); +echo "\n"; +?> +
  
  
<?php echo $strWithChecked; ?>    + + 1) { + ?> +    +
- - -
@@ -1052,6 +1051,8 @@ if (MYSQL_INT_VERSION >= 32322) { } // end if isset($tmp['Variable_name']) } // end while } // end if $result + + mysql_free_result($result); echo "\n"; ?>