optimized a bit (mainly added some 'mysql_free_result')

This commit is contained in:
Loïc Chapeaux
2001-09-06 10:16:44 +00:00
parent 661b19f210
commit c41de7a1f0
6 changed files with 84 additions and 56 deletions

View File

@@ -19,6 +19,8 @@ $Source$
support-). support-).
* lang/czech-iso.inc.php3 & czech-win1250.inc.php3: updated thanks to * lang/czech-iso.inc.php3 & czech-win1250.inc.php3: updated thanks to
Michal Cihar. 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<4C>c Chapeaux <lolo@phpheaven.net> 2001-09-05 Lo<4C>c Chapeaux <lolo@phpheaven.net>
* lib.inc.php3: * lib.inc.php3:

View File

@@ -52,8 +52,8 @@ if (mysql_error() != '') {
if ($num_tables > 0 && MYSQL_INT_VERSION >= 32303) { if ($num_tables > 0 && MYSQL_INT_VERSION >= 32303) {
// Special speedup for newer MySQL Versions (in 4.0 format changed) // Special speedup for newer MySQL Versions (in 4.0 format changed)
if ($cfgSkipLockedTables == TRUE && MYSQL_INT_VERSION >= 32330) { if ($cfgSkipLockedTables == TRUE && MYSQL_INT_VERSION >= 32330) {
$query = 'SHOW OPEN TABLES FROM ' . backquote($db); $local_query = 'SHOW OPEN TABLES FROM ' . backquote($db);
$result = mysql_query($query); $result = mysql_query($query) or mysql_die('', $local_query);
// Blending out tables in use // Blending out tables in use
if ($result != FALSE && mysql_num_rows($result) > 0) { if ($result != FALSE && mysql_num_rows($result) > 0) {
while ($tmp = mysql_fetch_array($result)) { while ($tmp = mysql_fetch_array($result)) {
@@ -65,13 +65,14 @@ if ($num_tables > 0 && MYSQL_INT_VERSION >= 32303) {
mysql_free_result($result); mysql_free_result($result);
if (isset($sot_cache)) { if (isset($sot_cache)) {
$query = 'SHOW TABLES FROM ' . backquote($db); $local_query = 'SHOW TABLES FROM ' . backquote($db);
$result = mysql_query($query); $result = mysql_query($query) or mysql_die('', $local_query);
if ($result != FALSE && mysql_num_rows($result) > 0) { if ($result != FALSE && mysql_num_rows($result) > 0) {
while ($tmp = mysql_fetch_array($result)) { while ($tmp = mysql_fetch_array($result)) {
if (!isset($sot_cache[$tmp[0]])) { if (!isset($sot_cache[$tmp[0]])) {
$sts_result = mysql_query('SHOW TABLE STATUS FROM ' . backquote($db) . ' LIKE \'' . addslashes($tmp[0]) . '\''); $local_query = 'SHOW TABLE STATUS FROM ' . backquote($db) . ' LIKE \'' . addslashes($tmp[0]) . '\'';
$sts_tmp = mysql_fetch_array($sts_result); $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; $tbl_cache[] = $sts_tmp;
} else { // table in use } else { // table in use
$tbl_cache[] = array('Name' => $tmp[0]); $tbl_cache[] = array('Name' => $tmp[0]);
@@ -84,7 +85,8 @@ if ($num_tables > 0 && MYSQL_INT_VERSION >= 32303) {
} }
} }
if (!isset($sot_ready)) { 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) { if ($result != FALSE && mysql_num_rows($result) > 0) {
while ($sts_tmp = mysql_fetch_array($result)) { while ($sts_tmp = mysql_fetch_array($result)) {
$tbl_cache[] = $sts_tmp; $tbl_cache[] = $sts_tmp;
@@ -338,7 +340,7 @@ else {
</tr> </tr>
<?php <?php
$i++; $i++;
} } // end while
echo "\n"; echo "\n";
?> ?>
<tr> <tr>
@@ -468,8 +470,9 @@ if ($num_tables > 0) {
<tr> <tr>
<?php <?php
$colspan = ''; $colspan = '';
$tables = mysql_list_tables($db); // loic1: already defined at the top of the script!
$num_tables = @mysql_numrows($tables); // $tables = mysql_list_tables($db);
// $num_tables = @mysql_numrows($tables);
if ($num_tables > 1) { if ($num_tables > 1) {
$colspan = ' colspan="2"'; $colspan = ' colspan="2"';
echo "\n"; echo "\n";
@@ -488,7 +491,9 @@ if ($num_tables > 0) {
</select> </select>
</td> </td>
<?php <?php
} } // end if
mysql_free_result($tables);
echo "\n"; echo "\n";
?> ?>
<td valign="middle"> <td valign="middle">

View File

@@ -72,7 +72,8 @@ if ($server > 0) {
} else { } else {
$true_dblist[$a_db->Database] = ''; $true_dblist[$a_db->Database] = '';
} }
} } // end while
mysql_free_result($dbs);
if ($num_dbs && empty($true_dblist)) { if ($num_dbs && empty($true_dblist)) {
$dblist = array(); $dblist = array();
} else if ($num_dbs) { } else if ($num_dbs) {
@@ -211,6 +212,7 @@ if ($num_dbs > 0) {
// Number of tables // Number of tables
$dbs_array[$db][0] = @mysql_numrows($tables); $dbs_array[$db][0] = @mysql_numrows($tables);
mysql_free_result($tables);
$total_array[0] += $dbs_array[$db][0]; $total_array[0] += $dbs_array[$db][0];
// Size of data and indexes // Size of data and indexes
@@ -230,8 +232,10 @@ if ($num_dbs > 0) {
$total_array[1] += $dbs_array[$db][1]; $total_array[1] += $dbs_array[$db][1];
$total_array[2] += $dbs_array[$db][2]; $total_array[2] += $dbs_array[$db][2];
$total_array[3] += $dbs_array[$db][3]; $total_array[3] += $dbs_array[$db][3];
} } // end if
mysql_free_result($result);
} // end for } // end for
mysql_close();
// Sorts the dbs arrays // Sorts the dbs arrays
uksort($dbs_array, 'pmaDbCmp'); uksort($dbs_array, 'pmaDbCmp');

View File

@@ -373,6 +373,7 @@ if (!defined('__LIB_INC__')){
// Seems to be a valid login... // Seems to be a valid login...
else { else {
$row = mysql_fetch_array($rs); $row = mysql_fetch_array($rs);
mysql_free_result($rs);
// Correction uva 19991215 // Correction uva 19991215
// Previous code assumed database "mysql" admin table "db" // Previous code assumed database "mysql" admin table "db"
// column "db" contains literal name of user database, and // column "db" contains literal name of user database, and
@@ -397,6 +398,7 @@ if (!defined('__LIB_INC__')){
while ($row = mysql_fetch_array($rs)) { while ($row = mysql_fetch_array($rs)) {
$dblist[] = $row['Db']; $dblist[] = $row['Db'];
} }
mysql_free_result($rs);
} }
} else { } else {
// Will use as associative array of the following 2 // Will use as associative array of the following 2
@@ -413,6 +415,7 @@ if (!defined('__LIB_INC__')){
while ($row = mysql_fetch_array($rs)) { while ($row = mysql_fetch_array($rs)) {
$uva_mydbs[$row['Db']] = 1; $uva_mydbs[$row['Db']] = 1;
} }
mysql_free_result($rs);
$uva_alldbs = mysql_list_dbs(); $uva_alldbs = mysql_list_dbs();
while ($uva_row = mysql_fetch_array($uva_alldbs)) { while ($uva_row = mysql_fetch_array($uva_alldbs)) {
$uva_db = $uva_row[0]; $uva_db = $uva_row[0];
@@ -432,6 +435,7 @@ if (!defined('__LIB_INC__')){
} // end while } // end while
} // end if ... else .... } // end if ... else ....
} // end while } // end while
mysql_free_result($uva_alldbs);
} // end else } // end else
} // end if } // end if
} // end else } // end else
@@ -659,8 +663,9 @@ if (!defined('__LIB_INC__')){
*/ */
function count_records($db, $table, $ret = FALSE) function count_records($db, $table, $ret = FALSE)
{ {
$result = mysql_query('select count(*) as num from ' . backquote($db) . '.' . backquote($table)); $result = mysql_query('SELECT COUNT(*) AS num FROM ' . backquote($db) . '.' . backquote($table));
$num = mysql_result($result,0,"num"); $num = mysql_result($result, 0, 'num');
mysql_free_result($result);
if ($ret) { if ($ret) {
return $num; return $num;
} else { } else {
@@ -996,6 +1001,7 @@ window.parent.frames['nav'].location.replace('<?php echo $reload_url; ?>');
$local_query = 'SELECT COUNT(*) AS total FROM ' . backquote($db) . '.' . backquote($table); $local_query = 'SELECT COUNT(*) AS total FROM ' . backquote($db) . '.' . backquote($table);
$result = mysql_query($local_query) or mysql_die('', $local_query); $result = mysql_query($local_query) or mysql_die('', $local_query);
$the_total = mysql_result($result, 0, 'total'); $the_total = mysql_result($result, 0, 'total');
mysql_free_result($result);
} }
// 4. If navigation bar or sorting fields names urls should be // 4. If navigation bar or sorting fields names urls should be
@@ -1808,6 +1814,7 @@ window.parent.frames['nav'].location.replace('<?php echo $reload_url; ?>');
$tmpres = mysql_fetch_array($result); $tmpres = mysql_fetch_array($result);
$schema_create .= str_replace("\n", $crlf, html_format($tmpres[1])); $schema_create .= str_replace("\n", $crlf, html_format($tmpres[1]));
} }
mysql_free_result($result);
return $schema_create; return $schema_create;
} // end if MySQL >= 3.23.20 } // end if MySQL >= 3.23.20
@@ -1829,6 +1836,7 @@ window.parent.frames['nav'].location.replace('<?php echo $reload_url; ?>');
} }
$schema_create .= ',' . $crlf; $schema_create .= ',' . $crlf;
} // end while } // end while
mysql_free_result($result);
$schema_create = ereg_replace(',' . $crlf . '$', '', $schema_create); $schema_create = ereg_replace(',' . $crlf . '$', '', $schema_create);
$local_query = 'SHOW KEYS FROM ' . backquote($db) . '.' . backquote($table); $local_query = 'SHOW KEYS FROM ' . backquote($db) . '.' . backquote($table);
@@ -1854,6 +1862,7 @@ window.parent.frames['nav'].location.replace('<?php echo $reload_url; ?>');
$index[$kname][] = html_format(backquote($row['Column_name'], $use_backquotes)); $index[$kname][] = html_format(backquote($row['Column_name'], $use_backquotes));
} }
} // end while } // end while
mysql_free_result($result);
while (list($x, $columns) = @each($index)) { while (list($x, $columns) = @each($index)) {
$schema_create .= ',' . $crlf; $schema_create .= ',' . $crlf;
@@ -1984,6 +1993,7 @@ window.parent.frames['nav'].location.replace('<?php echo $reload_url; ?>');
$GLOBALS['tmp_buffer'] = ereg_replace(',([^,]*)$', ';\\1', $GLOBALS['tmp_buffer']); $GLOBALS['tmp_buffer'] = ereg_replace(',([^,]*)$', ';\\1', $GLOBALS['tmp_buffer']);
} }
} // end if ($result != FALSE) } // end if ($result != FALSE)
mysql_free_result($result);
return TRUE; return TRUE;
} // end of the 'get_table_content_fast()' function } // end of the 'get_table_content_fast()' function
@@ -2019,12 +2029,13 @@ window.parent.frames['nav'].location.replace('<?php echo $reload_url; ?>');
$result = mysql_query($local_query) or mysql_die('', $local_query); $result = mysql_query($local_query) or mysql_die('', $local_query);
$i = 0; $i = 0;
$isFirstRow = TRUE; $isFirstRow = TRUE;
$fields_cnt = mysql_num_fields($result);
while ($row = mysql_fetch_row($result)) { while ($row = mysql_fetch_row($result)) {
@set_time_limit(60); // HaRa @set_time_limit(60); // HaRa
$table_list = '('; $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) . ', '; $table_list .= backquote(mysql_field_name($result, $j), $use_backquotes) . ', ';
} }
@@ -2044,7 +2055,7 @@ window.parent.frames['nav'].location.replace('<?php echo $reload_url; ?>');
$isFirstRow = FALSE; $isFirstRow = FALSE;
} }
for ($j = 0; $j < mysql_num_fields($result); $j++) { for ($j = 0; $j < $fields_cnt; $j++) {
if (!isset($row[$j])) { if (!isset($row[$j])) {
$schema_insert .= ' NULL,'; $schema_insert .= ' NULL,';
} else if ($row[$j] != '') { } else if ($row[$j] != '') {
@@ -2073,6 +2084,7 @@ window.parent.frames['nav'].location.replace('<?php echo $reload_url; ?>');
$handler(trim($schema_insert)); $handler(trim($schema_insert));
++$i; ++$i;
} // end while } // end while
mysql_free_result($result);
// Replace last comma by a semi-column in extended inserts case // Replace last comma by a semi-column in extended inserts case
if ($i > 0 && isset($GLOBALS['extended_ins'])) { if ($i > 0 && isset($GLOBALS['extended_ins'])) {
@@ -2191,13 +2203,13 @@ window.parent.frames['nav'].location.replace('<?php echo $reload_url; ?>');
// Gets the data from the database // Gets the data from the database
$local_query = 'SELECT * FROM ' . backquote($db) . '.' . backquote($table) . $add_query; $local_query = 'SELECT * FROM ' . backquote($db) . '.' . backquote($table) . $add_query;
$result = mysql_query($local_query) or mysql_die('', $local_query); $result = mysql_query($local_query) or mysql_die('', $local_query);
$fields_cnt = mysql_num_fields($result);
// Format the data // Format the data
$i = 0; $i = 0;
while ($row = mysql_fetch_row($result)) { while ($row = mysql_fetch_row($result)) {
@set_time_limit(60); @set_time_limit(60);
$schema_insert = ''; $schema_insert = '';
$fields_cnt = mysql_num_fields($result);
for ($j = 0; $j < $fields_cnt; $j++) { for ($j = 0; $j < $fields_cnt; $j++) {
if (!isset($row[$j])) { if (!isset($row[$j])) {
$schema_insert .= 'NULL'; $schema_insert .= 'NULL';
@@ -2221,6 +2233,7 @@ window.parent.frames['nav'].location.replace('<?php echo $reload_url; ?>');
$handler(trim($schema_insert)); $handler(trim($schema_insert));
++$i; ++$i;
} // end while } // end while
mysql_free_result($result);
return TRUE; return TRUE;
} // end of the 'get_table_csv()' function } // end of the 'get_table_csv()' function

View File

@@ -198,6 +198,7 @@ else {
} else { } else {
$num_rows = 0; $num_rows = 0;
} }
mysql_free_result($OPresult);
} }
// Executes the query // Executes the query
@@ -232,6 +233,7 @@ else {
if ($OPresult) { if ($OPresult) {
$unlim_num_rows = mysql_result($OPresult, 0, 'count'); $unlim_num_rows = mysql_result($OPresult, 0, 'count');
} }
mysql_free_result($OPresult);
} else { } else {
$unlim_num_rows = 0; $unlim_num_rows = 0;
} }
@@ -301,6 +303,7 @@ else {
$disp_mode = 'urdr11110'; $disp_mode = 'urdr11110';
} }
display_table($result, $disp_mode); display_table($result, $disp_mode);
mysql_free_result($result);
// Displays "Insert a new row" link if required // Displays "Insert a new row" link if required
if ($disp_mode[6] == '1') { if ($disp_mode[6] == '1') {

View File

@@ -63,6 +63,8 @@ if (!empty($table)) {
if (empty($table) || !@mysql_numrows($is_table)) { if (empty($table) || !@mysql_numrows($is_table)) {
header('Location: ' . $cfgPmaAbsoluteUri . 'db_details.php3?lang=' . $lang . '&server=' . $server . '&db=' . urlencode($db) . '&reload=true'); header('Location: ' . $cfgPmaAbsoluteUri . 'db_details.php3?lang=' . $lang . '&server=' . $server . '&db=' . urlencode($db) . '&reload=true');
exit(); exit();
} else {
mysql_free_result($result);
} }
@@ -118,6 +120,7 @@ if (MYSQL_INT_VERSION >= 32303) {
$num_rows = mysql_result($result, 0, 'count'); $num_rows = mysql_result($result, 0, 'count');
$show_comment = ''; $show_comment = '';
} }
mysql_free_result($result);
?> ?>
<?php <?php
@@ -171,14 +174,31 @@ if (!empty($show_comment)) {
$local_query = 'SHOW KEYS FROM ' . backquote($table); $local_query = 'SHOW KEYS FROM ' . backquote($table);
$result = mysql_query($local_query) or mysql_die('', $local_query); $result = mysql_query($local_query) or mysql_die('', $local_query);
$primary = ''; $primary = '';
$pk_array = array(); $prev_key = '';
$prev_seq = 0;
$i = 0;
$pk_array = array(); // will be use to emphasis prim. keys in the table view
while($row = mysql_fetch_array($result)) { while($row = mysql_fetch_array($result)) {
$ret_keys[] = $row; $ret_keys[] = $row;
// Unset the 'Seq_in_index' value if it's not a composite index - part 1
if ($i > 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') { if ($row['Key_name'] == 'PRIMARY') {
$primary .= $row['Column_name'] . ', '; $primary .= $row['Column_name'] . ', ';
$pk_array[$row['Column_name']] = 1; $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 // 3. Get fields
$local_query = 'SHOW FIELDS FROM ' . backquote($table); $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); $fields_cnt = mysql_num_rows($result);
/** /**
* Displays the table structure ('show table' works correct since 3.23.03) * Displays the table structure ('show table' works correct since 3.23.03)
*/ */
?> ?>
<!-- TABLE INFORMATIONS --> <!-- TABLE INFORMATIONS -->
<?php
// Drop button if there is at least two fields
if ($fields_cnt > 1) {
?>
<form action="tbl_properties.php3"> <form action="tbl_properties.php3">
<input type="hidden" name="lang" value="<?php echo $lang; ?>" /> <input type="hidden" name="lang" value="<?php echo $lang; ?>" />
<input type="hidden" name="server" value="<?php echo $server; ?>" /> <input type="hidden" name="server" value="<?php echo $server; ?>" />
<input type="hidden" name="db" value="<?php echo $db; ?>" /> <input type="hidden" name="db" value="<?php echo $db; ?>" />
<input type="hidden" name="table" value="<?php echo $table; ?>" /> <input type="hidden" name="table" value="<?php echo $table; ?>" />
<?php
}
echo "\n";
?>
<table border="<?php echo $cfgBorder; ?>"> <table border="<?php echo $cfgBorder; ?>">
<tr> <tr>
<?php <td></td>
// Drop button if there is at least two fields
if ($fields_cnt > 1) {
echo ' <td></td>' . "\n";
}
?>
<th>&nbsp;<?php echo ucfirst($strField); ?>&nbsp;</th> <th>&nbsp;<?php echo ucfirst($strField); ?>&nbsp;</th>
<th><?php echo ucfirst($strType); ?></th> <th><?php echo ucfirst($strType); ?></th>
<th><?php echo ucfirst($strAttr); ?></th> <th><?php echo ucfirst($strAttr); ?></th>
@@ -280,17 +286,9 @@ while ($row = mysql_fetch_array($result)) {
echo "\n"; echo "\n";
?> ?>
<tr bgcolor="<?php echo $bgcolor; ?>"> <tr bgcolor="<?php echo $bgcolor; ?>">
<?php
// Drop button if there is at least two fields
if ($fields_cnt > 1) {
?>
<td align="center"> <td align="center">
<input type="checkbox" name="selected_fld[]" value="<?php echo urlencode($row['Field']); ?>" /> <input type="checkbox" name="selected_fld[]" value="<?php echo urlencode($row['Field']); ?>" />
</td> </td>
<?php
}
echo "\n";
?>
<td nowrap="nowrap">&nbsp;<?php echo $field_name; ?>&nbsp;</td> <td nowrap="nowrap">&nbsp;<?php echo $field_name; ?>&nbsp;</td>
<td<?php echo $type_nowrap; ?>><?php echo $type; ?></td> <td<?php echo $type_nowrap; ?>><?php echo $type; ?></td>
<td nowrap="nowrap"><?php echo $strAttribute; ?></td> <td nowrap="nowrap"><?php echo $strAttribute; ?></td>
@@ -333,30 +331,31 @@ while ($row = mysql_fetch_array($result)) {
</tr> </tr>
<?php <?php
} // end while } // end while
echo "\n";
// Drop button if there is at least two fields mysql_free_result($result);
if ($fields_cnt > 1) { echo "\n";
?> ?>
<tr> <tr>
<td colspan="12"> <td colspan="12">
<img src="./images/arrow.gif" border="0" width="38" height="22" alt="<?php echo $strWithChecked; ?>" /> <img src="./images/arrow.gif" border="0" width="38" height="22" alt="<?php echo $strWithChecked; ?>" />
<i><?php echo $strWithChecked; ?></i>&nbsp;&nbsp; <i><?php echo $strWithChecked; ?></i>&nbsp;&nbsp;
<input type="submit" name="submit_mult" value="<?php echo $strChange; ?>" />
<?php
// Drop button if there is at least two fields
if ($fields_cnt > 1) {
?>
&nbsp;<i><?php echo $strOr; ?></i>&nbsp;
<input type="submit" name="submit_mult" value="<?php echo $strDrop; ?>" /> <input type="submit" name="submit_mult" value="<?php echo $strDrop; ?>" />
<?php
}
echo "\n";
?>
</td> </td>
<tr> <tr>
</table> </table>
</form> </form>
<?php
} else {
echo "\n"
?>
</table>
<?php
}
echo "\n";
?>
<br /> <br />
@@ -1052,6 +1051,8 @@ if (MYSQL_INT_VERSION >= 32322) {
} // end if isset($tmp['Variable_name']) } // end if isset($tmp['Variable_name'])
} // end while } // end while
} // end if $result } // end if $result
mysql_free_result($result);
echo "\n"; echo "\n";
?> ?>
<li> <li>