optimized a bit (mainly added some 'mysql_free_result')
This commit is contained in:
@@ -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<4C>c Chapeaux <lolo@phpheaven.net>
|
||||
* lib.inc.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 {
|
||||
</tr>
|
||||
<?php
|
||||
$i++;
|
||||
}
|
||||
} // end while
|
||||
echo "\n";
|
||||
?>
|
||||
<tr>
|
||||
@@ -468,8 +470,9 @@ if ($num_tables > 0) {
|
||||
<tr>
|
||||
<?php
|
||||
$colspan = '';
|
||||
$tables = mysql_list_tables($db);
|
||||
$num_tables = @mysql_numrows($tables);
|
||||
// loic1: already defined at the top of the script!
|
||||
// $tables = mysql_list_tables($db);
|
||||
// $num_tables = @mysql_numrows($tables);
|
||||
if ($num_tables > 1) {
|
||||
$colspan = ' colspan="2"';
|
||||
echo "\n";
|
||||
@@ -488,7 +491,9 @@ if ($num_tables > 0) {
|
||||
</select>
|
||||
</td>
|
||||
<?php
|
||||
}
|
||||
} // end if
|
||||
mysql_free_result($tables);
|
||||
|
||||
echo "\n";
|
||||
?>
|
||||
<td valign="middle">
|
||||
|
@@ -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');
|
||||
|
23
lib.inc.php3
23
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('<?php echo $reload_url; ?>');
|
||||
$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('<?php echo $reload_url; ?>');
|
||||
$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('<?php echo $reload_url; ?>');
|
||||
}
|
||||
$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('<?php echo $reload_url; ?>');
|
||||
$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('<?php echo $reload_url; ?>');
|
||||
$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('<?php echo $reload_url; ?>');
|
||||
$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('<?php echo $reload_url; ?>');
|
||||
$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('<?php echo $reload_url; ?>');
|
||||
$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('<?php echo $reload_url; ?>');
|
||||
// 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('<?php echo $reload_url; ?>');
|
||||
$handler(trim($schema_insert));
|
||||
++$i;
|
||||
} // end while
|
||||
mysql_free_result($result);
|
||||
|
||||
return TRUE;
|
||||
} // end of the 'get_table_csv()' function
|
||||
|
3
sql.php3
3
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') {
|
||||
|
@@ -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);
|
||||
?>
|
||||
|
||||
<?php
|
||||
@@ -171,14 +174,31 @@ if (!empty($show_comment)) {
|
||||
$local_query = 'SHOW KEYS FROM ' . backquote($table);
|
||||
$result = mysql_query($local_query) or mysql_die('', $local_query);
|
||||
$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)) {
|
||||
$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') {
|
||||
$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)
|
||||
*/
|
||||
?>
|
||||
|
||||
|
||||
|
||||
<!-- TABLE INFORMATIONS -->
|
||||
|
||||
<?php
|
||||
// Drop button if there is at least two fields
|
||||
if ($fields_cnt > 1) {
|
||||
?>
|
||||
<form action="tbl_properties.php3">
|
||||
<input type="hidden" name="lang" value="<?php echo $lang; ?>" />
|
||||
<input type="hidden" name="server" value="<?php echo $server; ?>" />
|
||||
<input type="hidden" name="db" value="<?php echo $db; ?>" />
|
||||
<input type="hidden" name="table" value="<?php echo $table; ?>" />
|
||||
<?php
|
||||
}
|
||||
echo "\n";
|
||||
?>
|
||||
|
||||
<table border="<?php echo $cfgBorder; ?>">
|
||||
<tr>
|
||||
<?php
|
||||
// Drop button if there is at least two fields
|
||||
if ($fields_cnt > 1) {
|
||||
echo ' <td></td>' . "\n";
|
||||
}
|
||||
?>
|
||||
<td></td>
|
||||
<th> <?php echo ucfirst($strField); ?> </th>
|
||||
<th><?php echo ucfirst($strType); ?></th>
|
||||
<th><?php echo ucfirst($strAttr); ?></th>
|
||||
@@ -280,17 +286,9 @@ while ($row = mysql_fetch_array($result)) {
|
||||
echo "\n";
|
||||
?>
|
||||
<tr bgcolor="<?php echo $bgcolor; ?>">
|
||||
<?php
|
||||
// Drop button if there is at least two fields
|
||||
if ($fields_cnt > 1) {
|
||||
?>
|
||||
<td align="center">
|
||||
<input type="checkbox" name="selected_fld[]" value="<?php echo urlencode($row['Field']); ?>" />
|
||||
</td>
|
||||
<?php
|
||||
}
|
||||
echo "\n";
|
||||
?>
|
||||
<td nowrap="nowrap"> <?php echo $field_name; ?> </td>
|
||||
<td<?php echo $type_nowrap; ?>><?php echo $type; ?></td>
|
||||
<td nowrap="nowrap"><?php echo $strAttribute; ?></td>
|
||||
@@ -333,30 +331,31 @@ while ($row = mysql_fetch_array($result)) {
|
||||
</tr>
|
||||
<?php
|
||||
} // end while
|
||||
echo "\n";
|
||||
|
||||
// Drop button if there is at least two fields
|
||||
if ($fields_cnt > 1) {
|
||||
?>
|
||||
mysql_free_result($result);
|
||||
echo "\n";
|
||||
?>
|
||||
|
||||
<tr>
|
||||
<td colspan="12">
|
||||
<img src="./images/arrow.gif" border="0" width="38" height="22" alt="<?php echo $strWithChecked; ?>" />
|
||||
<i><?php echo $strWithChecked; ?></i>
|
||||
<input type="submit" name="submit_mult" value="<?php echo $strChange; ?>" />
|
||||
<?php
|
||||
// Drop button if there is at least two fields
|
||||
if ($fields_cnt > 1) {
|
||||
?>
|
||||
<i><?php echo $strOr; ?></i>
|
||||
<input type="submit" name="submit_mult" value="<?php echo $strDrop; ?>" />
|
||||
<?php
|
||||
}
|
||||
echo "\n";
|
||||
?>
|
||||
</td>
|
||||
<tr>
|
||||
</table>
|
||||
|
||||
</form>
|
||||
<?php
|
||||
} else {
|
||||
echo "\n"
|
||||
?>
|
||||
</table>
|
||||
<?php
|
||||
}
|
||||
echo "\n";
|
||||
?>
|
||||
<br />
|
||||
|
||||
|
||||
@@ -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";
|
||||
?>
|
||||
<li>
|
||||
|
Reference in New Issue
Block a user