Optimization - do not call "mysql_numrows", "mysql_results" and "mysql_fetch_array" on invalid queries
This commit is contained in:
@@ -20,6 +20,8 @@ $Source$
|
||||
under php 3.0.12 thanks to Kris Wood <kris at navi.net>.
|
||||
* libraries/common.lib.php3, line 791: fixed a warning thanks to
|
||||
Kris Wood <kris at navi.net>.
|
||||
* mosts scripts: optimization - do not call "mysql_numrows",
|
||||
"mysql_results" and "mysql_fetch_array" on invalid queries.
|
||||
|
||||
2002-04-30 Lo<4C>c Chapeaux <lolo@phpheaven.net>
|
||||
* lang/italian.inc.php3: updated thanks to Pietro Danesi.
|
||||
|
@@ -121,7 +121,7 @@ if (PMA_MYSQL_INT_VERSION >= 32303) {
|
||||
} // end if (PMA_MYSQL_INT_VERSION >= 32303)
|
||||
else {
|
||||
$result = mysql_list_tables($db);
|
||||
$num_tables = @mysql_numrows($result);
|
||||
$num_tables = ($result) ? @mysql_numrows($result) : 0;
|
||||
for ($i = 0; $i < $num_tables; $i++) {
|
||||
$tables[] = mysql_tablename($result, $i);
|
||||
}
|
||||
@@ -638,9 +638,6 @@ if ($num_tables > 0) {
|
||||
<tr>
|
||||
<?php
|
||||
$colspan = '';
|
||||
// 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";
|
||||
|
@@ -72,7 +72,7 @@ if (PMA_MYSQL_INT_VERSION >= 32303) {
|
||||
} // end if (PMA_MYSQL_INT_VERSION >= 32303)
|
||||
else {
|
||||
$result = mysql_list_tables($db);
|
||||
$num_tables = @mysql_numrows($result);
|
||||
$num_tables = ($result) ? @mysql_numrows($result) : 0;
|
||||
for ($i = 0; $i < $num_tables; $i++) {
|
||||
$tables[] = mysql_tablename($result, $i);
|
||||
}
|
||||
|
@@ -228,7 +228,7 @@ if ($num_dbs > 0) {
|
||||
$tables = @mysql_list_tables($db);
|
||||
|
||||
// Number of tables
|
||||
$dbs_array[$db][0] = @mysql_numrows($tables);
|
||||
$dbs_array[$db][0] = ($tables) ? @mysql_numrows($tables) : 0;
|
||||
mysql_free_result($tables);
|
||||
$total_array[0] += $dbs_array[$db][0];
|
||||
|
||||
@@ -241,7 +241,7 @@ if ($num_dbs > 0) {
|
||||
$local_query = 'SHOW TABLE STATUS FROM ' . PMA_backquote($db);
|
||||
$result = @mysql_query($local_query);
|
||||
// needs the "@" below otherwise, warnings in case of special DB names
|
||||
if (@mysql_num_rows($result)) {
|
||||
if ($result && @mysql_num_rows($result)) {
|
||||
while ($row = mysql_fetch_array($result)) {
|
||||
$dbs_array[$db][1] += $row['Data_length'];
|
||||
$dbs_array[$db][2] += $row['Index_length'];
|
||||
|
@@ -207,7 +207,7 @@ if ($num_dbs > 1) {
|
||||
$selected_db = $j;
|
||||
}
|
||||
$tables = @mysql_list_tables($db);
|
||||
$num_tables = @mysql_numrows($tables);
|
||||
$num_tables = ($tables) ? @mysql_numrows($tables) : 0;
|
||||
$common_url_query = 'lang=' . $lang
|
||||
. '&server=' . $server
|
||||
. '&db=' . urlencode($db);
|
||||
@@ -374,7 +374,7 @@ if ($num_dbs > 1) {
|
||||
else if ($num_dbs == 1) {
|
||||
$db = $dblist[0];
|
||||
$tables = @mysql_list_tables($db);
|
||||
$num_tables = @mysql_numrows($tables);
|
||||
$num_tables = ($tables) ? @mysql_numrows($tables) : 0;
|
||||
$common_url_query = 'lang=' . $lang
|
||||
. '&server=' . $server
|
||||
. '&db=' . urlencode($db);
|
||||
|
@@ -504,7 +504,7 @@ if (!defined('PMA_COMMON_LIB_INCLUDED')){
|
||||
if (PMA_MYSQL_INT_VERSION >= 32330) {
|
||||
$local_query = 'SHOW VARIABLES LIKE \'safe_show_database\'';
|
||||
$rs = mysql_query($local_query, $dbh); // Debug: or PMA_mysqlDie('', $local_query, FALSE);
|
||||
$is_safe_show_dbs = @mysql_result($rs, 0, 'Value');
|
||||
$is_safe_show_dbs = ($rs) ? @mysql_result($rs, 0, 'Value') : FALSE;
|
||||
|
||||
// ... and if on, try to get the available dbs list
|
||||
if ($is_safe_show_dbs && strtoupper($is_safe_show_dbs) != 'OFF') {
|
||||
@@ -529,7 +529,8 @@ if (!defined('PMA_COMMON_LIB_INCLUDED')){
|
||||
|
||||
// Access to "mysql" db allowed and dblist still empty -> gets the
|
||||
// usable db list
|
||||
if (!$dblist_cnt && @mysql_numrows($rs)) {
|
||||
if (!$dblist_cnt
|
||||
&& ($rs && @mysql_numrows($rs))) {
|
||||
$row = mysql_fetch_array($rs);
|
||||
mysql_free_result($rs);
|
||||
// Correction uva 19991215
|
||||
@@ -548,7 +549,7 @@ if (!defined('PMA_COMMON_LIB_INCLUDED')){
|
||||
// lem9: User can be blank (anonymous user)
|
||||
$local_query = 'SELECT DISTINCT Db FROM mysql.db WHERE Select_priv = \'Y\' AND (User = \'' . PMA_sqlAddslashes($cfg['Server']['user']) . '\' OR User = \'\')';
|
||||
$rs = mysql_query($local_query, $dbh); // Debug: or PMA_mysqlDie('', $local_query, FALSE);
|
||||
if (@mysql_numrows($rs)) {
|
||||
if ($rs && @mysql_numrows($rs)) {
|
||||
// Will use as associative array of the following 2 code
|
||||
// lines:
|
||||
// the 1st is the only line intact from before
|
||||
@@ -609,7 +610,7 @@ if (!defined('PMA_COMMON_LIB_INCLUDED')){
|
||||
// 2. get allowed dbs from the "mysql.tables_priv" table
|
||||
$local_query = 'SELECT DISTINCT Db FROM mysql.tables_priv WHERE Table_priv LIKE \'%Select%\' AND User = \'' . PMA_sqlAddslashes($cfg['Server']['user']) . '\'';
|
||||
$rs = mysql_query($local_query, $dbh); // Debug: or PMA_mysqlDie('', $local_query, FALSE);
|
||||
if (@mysql_numrows($rs)) {
|
||||
if ($rs && @mysql_numrows($rs)) {
|
||||
while ($row = mysql_fetch_array($rs)) {
|
||||
if (PMA_isInto($row['Db'], $dblist) == -1) {
|
||||
$dblist[] = $row['Db'];
|
||||
@@ -667,7 +668,7 @@ if (!defined('PMA_COMMON_LIB_INCLUDED')){
|
||||
// on the server
|
||||
else {
|
||||
$dbs = mysql_list_dbs() or PMA_mysqlDie('', 'mysql_list_dbs()', FALSE, $error_url);
|
||||
$num_dbs = @mysql_num_rows($dbs);
|
||||
$num_dbs = ($dbs) ? @mysql_num_rows($dbs) : 0;
|
||||
$real_num_dbs = 0;
|
||||
for ($i = 0; $i < $num_dbs; $i++) {
|
||||
$db_name_tmp = mysql_dbname($dbs, $i);
|
||||
|
@@ -228,7 +228,7 @@ if ($server > 0) {
|
||||
$db_to_create = '';
|
||||
break;
|
||||
} // end if
|
||||
elseif (ereg($re . '%|_', $show_grants_dbname) || !mysql_select_db($show_grants_dbname, $userlink) && @mysql_errno() != 1044) {
|
||||
else if (ereg($re . '%|_', $show_grants_dbname) || !mysql_select_db($show_grants_dbname, $userlink) && @mysql_errno() != 1044) {
|
||||
$show_grants_dbname = ereg_replace($re . '%', '\\1...', ereg_replace($re . '_', '\\1?', $show_grants_dbname));
|
||||
$db_to_create = $show_grants_dbname;
|
||||
$is_create_priv = TRUE;
|
||||
|
@@ -386,7 +386,7 @@ if ($goto == 'tbl_properties.php3') {
|
||||
$goto = 'db_details.php3';
|
||||
} else {
|
||||
$is_table = @mysql_query('SHOW TABLES LIKE \'' . PMA_sqlAddslashes($table, TRUE) . '\'');
|
||||
if (!@mysql_numrows($is_table)) {
|
||||
if (!($is_table && @mysql_numrows($is_table))) {
|
||||
$goto = 'db_details.php3';
|
||||
unset($table);
|
||||
}
|
||||
|
4
sql.php3
4
sql.php3
@@ -283,7 +283,7 @@ else {
|
||||
|
||||
// Gets the number of rows affected/returned
|
||||
if (!$is_affected) {
|
||||
$num_rows = @mysql_num_rows($result);
|
||||
$num_rows = ($result) ? @mysql_num_rows($result) : 0;
|
||||
} else if (!isset($num_rows)) {
|
||||
$num_rows = @mysql_affected_rows();
|
||||
}
|
||||
@@ -345,7 +345,7 @@ else {
|
||||
$goto = 'db_details.php3';
|
||||
} else {
|
||||
$is_table = @mysql_query('SHOW TABLES LIKE \'' . PMA_sqlAddslashes($table, TRUE) . '\'');
|
||||
if (!@mysql_numrows($is_table)) {
|
||||
if (!($is_table && @mysql_numrows($is_table))) {
|
||||
$goto = 'db_details.php3';
|
||||
unset($table);
|
||||
}
|
||||
|
@@ -180,7 +180,7 @@ else {
|
||||
// Gets the number of tables if a dump of a database has been required
|
||||
if (!isset($table)) {
|
||||
$tables = mysql_list_tables($db);
|
||||
$num_tables = @mysql_numrows($tables);
|
||||
$num_tables = ($tables) ? @mysql_numrows($tables) : 0;
|
||||
} else {
|
||||
$num_tables = 1;
|
||||
$single = TRUE;
|
||||
|
@@ -39,9 +39,10 @@ if (!defined('PMA_IDX_INCLUDED')) {
|
||||
}
|
||||
// Not a valid table name -> back to the db_details.php3
|
||||
if (!empty($table)) {
|
||||
$is_table = @mysql_query("SHOW TABLES LIKE '" . PMA_sqlAddslashes($table, TRUE) . '\'');
|
||||
$is_table = @mysql_query('SHOW TABLES LIKE \'' . PMA_sqlAddslashes($table, TRUE) . '\'');
|
||||
}
|
||||
if (empty($table) || !@mysql_numrows($is_table)) {
|
||||
if (empty($table)
|
||||
|| !($is_table && @mysql_numrows($is_table))) {
|
||||
header('Location: ' . $cfg['PmaAbsoluteUri'] . 'db_details.php3?lang=' . $lang . '&server=' . $server . '&db=' . urlencode($db) . (isset($message) ? '&message=' . urlencode($message) : '') . '&reload=1');
|
||||
exit();
|
||||
} else if (isset($is_table)) {
|
||||
@@ -399,7 +400,7 @@ else if (!defined('PMA_IDX_INCLUDED')
|
||||
}
|
||||
echo ' <hr /><br />' . "\n";
|
||||
echo ' ' . sprintf($strAddToIndex, '<input type="text" name="added_fields" size="4" value="1" class="textfield" onfocus="this.select()" />') . "\n";
|
||||
echo ' <input type="submit" name="add_fields" value="' . $strGo . '" class="textfield" onclick="return checkFormElementInRange(this.form, \'added_fields\', 1)" />' . "\n";
|
||||
echo ' <input type="submit" name="add_fields" value="' . $strGo . '" onclick="return checkFormElementInRange(this.form, \'added_fields\', 1)" />' . "\n";
|
||||
|
||||
} else {
|
||||
/**
|
||||
|
@@ -43,7 +43,8 @@ if (!isset($is_table) || !$is_table) {
|
||||
if (!empty($table)) {
|
||||
$is_table = @mysql_query('SHOW TABLES LIKE \'' . PMA_sqlAddslashes($table, TRUE) . '\'');
|
||||
}
|
||||
if (empty($table) || !@mysql_numrows($is_table)) {
|
||||
if (empty($table)
|
||||
|| !($is_table && @mysql_numrows($is_table))) {
|
||||
header('Location: ' . $cfg['PmaAbsoluteUri'] . 'db_details.php3?lang=' . $lang . '&server=' . $server . '&db=' . urlencode($db) . (isset($message) ? '&message=' . urlencode($message) : '') . '&reload=1');
|
||||
exit();
|
||||
} else if (isset($is_table)) {
|
||||
|
@@ -74,7 +74,7 @@ function PMA_tableGrants(&$host_db_result, $dbcheck = FALSE) {
|
||||
while ($row = (is_array($host_db_result) ? $host_db_result : mysql_fetch_array($host_db_result))) {
|
||||
$local_query = 'SHOW GRANTS FOR \'' . $row['User'] . '\'@\'' . $row['Host'] . '\'';
|
||||
$result = mysql_query($local_query);
|
||||
$grants_cnt = @mysql_num_rows($result);
|
||||
$grants_cnt = ($result) ? @mysql_num_rows($result) : 0;
|
||||
|
||||
if ($grants_cnt) {
|
||||
$i = 0;
|
||||
@@ -221,7 +221,7 @@ function PMA_checkDb($dbcheck)
|
||||
{
|
||||
$local_query = 'SELECT Host, User FROM mysql.user ORDER BY Host, User';
|
||||
$result = mysql_query($local_query);
|
||||
$host_usr_cnt = @mysql_num_rows($result);
|
||||
$host_usr_cnt = ($result) ? @mysql_num_rows($result) : 0;
|
||||
|
||||
if (!$host_usr_cnt) {
|
||||
return FALSE;
|
||||
@@ -350,7 +350,7 @@ function PMA_normalOperations()
|
||||
<?php
|
||||
echo "\n";
|
||||
$result = mysql_query('SHOW DATABASES');
|
||||
if (@mysql_num_rows($result)) {
|
||||
if ($result && @mysql_num_rows($result)) {
|
||||
while ($row = mysql_fetch_row($result)) {
|
||||
echo ' ';
|
||||
echo '<option value="' . str_replace('"', '"', $row[0]) . '">' . htmlspecialchars($row[0]) . '</option>' . "\n";
|
||||
@@ -505,7 +505,7 @@ function PMA_grantOperations($grants)
|
||||
// }
|
||||
$is_selected_db = FALSE;
|
||||
$result = mysql_query('SHOW DATABASES');
|
||||
if (@mysql_num_rows($result)) {
|
||||
if ($result && @mysql_num_rows($result)) {
|
||||
while ($row = mysql_fetch_row($result)) {
|
||||
$selected = (($row[0] == $dbgrant) ? ' selected="selected"' : '');
|
||||
if (!empty($selected)) {
|
||||
@@ -544,7 +544,7 @@ function PMA_grantOperations($grants)
|
||||
// }
|
||||
if (isset($dbgrant)) {
|
||||
$result = mysql_query('SHOW TABLES FROM ' . PMA_backquote($dbgrant));
|
||||
if (@mysql_num_rows($result)) {
|
||||
if ($result && @mysql_num_rows($result)) {
|
||||
while ($row = mysql_fetch_row($result)) {
|
||||
$selected = ((isset($tablegrant) && $row[0] == $tablegrant) ? ' selected="selected"' : '');
|
||||
echo ' ';
|
||||
@@ -580,7 +580,7 @@ function PMA_grantOperations($grants)
|
||||
}
|
||||
else {
|
||||
$result = mysql_query('SHOW COLUMNS FROM ' . PMA_backquote($dbgrant) . '.' . PMA_backquote($tablegrant));
|
||||
if (@mysql_num_rows($result)) {
|
||||
if ($result && @mysql_num_rows($result)) {
|
||||
echo ' '
|
||||
. '<select name="colgrant[]" multiple="multiple" onchange="anycolumn[1].checked = true">' . "\n";
|
||||
while ($row = mysql_fetch_row($result)) {
|
||||
@@ -655,7 +655,7 @@ function PMA_editOperations($host, $user)
|
||||
global $lang, $server;
|
||||
|
||||
$result = mysql_query('SELECT * FROM mysql.user WHERE User = \'' . PMA_sqlAddslashes($user) . '\' AND Host = \'' . PMA_sqlAddslashes($host) . '\'');
|
||||
$rows = @mysql_num_rows($result);
|
||||
$rows = ($result) ? @mysql_num_rows($result) : 0;
|
||||
|
||||
if (!$rows) {
|
||||
return FALSE;
|
||||
@@ -790,7 +790,7 @@ function PMA_tableUsers($host = FALSE, $user = FALSE)
|
||||
}
|
||||
$local_query .= ' ORDER BY Host, User';
|
||||
$result = mysql_query($local_query);
|
||||
$rows = @mysql_num_rows($result);
|
||||
$rows = ($result) ? @mysql_num_rows($result) : 0;
|
||||
|
||||
if (!$rows) {
|
||||
return FALSE;
|
||||
@@ -870,11 +870,6 @@ function PMA_tableUsers($host = FALSE, $user = FALSE)
|
||||
$check_url = 'user_details.php3'
|
||||
. '?lang=' . $lang . '&server=' . $server
|
||||
. '&grants=1&host=' . urlencode($row['Host']) . '&pma_user=' . urlencode($row['User']);
|
||||
|
||||
// $check_result = mysql_query('SHOW GRANTS FOR \'' . $row['User'] . '\'@\'' . $row['Host'] . '\'');
|
||||
// if (@mysql_num_rows($check_result) == 0) {
|
||||
// $check_url = '';
|
||||
// }
|
||||
?>
|
||||
|
||||
<tr>
|
||||
@@ -1387,7 +1382,7 @@ else if (isset($grants) && $grants) {
|
||||
|
||||
// Gets globals privileges
|
||||
$result = mysql_query('SELECT * FROM mysql.user WHERE (Host = \'' . PMA_sqlAddslashes($host) . '\' OR Host = \'%\') AND (User = \'' . PMA_sqlAddslashes($pma_user) . '\' OR User = \'\')');
|
||||
$row = @mysql_fetch_array($result);
|
||||
$row = ($result) ? @mysql_fetch_array($result) : FALSE;
|
||||
if ($row) {
|
||||
while (list(,$priv) = each($list_priv)) {
|
||||
$priv_priv = $priv . '_priv';
|
||||
@@ -1410,7 +1405,7 @@ else if (isset($grants) && $grants) {
|
||||
$dbgrant = stripslashes($dbgrant);
|
||||
}
|
||||
$result = mysql_query('SELECT * FROM mysql.db WHERE (Host = \'' . PMA_sqlAddslashes($host) . '\' OR Host = \'%\') AND (User = \'' . PMA_sqlAddslashes($pma_user) . '\' OR User = \'\') AND Db = \'' . PMA_sqlAddslashes($dbgrant) . '\'');
|
||||
$row = @mysql_fetch_array($result);
|
||||
$row = ($result) ? @mysql_fetch_array($result) : FALSE;
|
||||
if ($row) {
|
||||
while (list(,$priv) = each($list_priv)) {
|
||||
$priv_priv = $priv . '_priv';
|
||||
@@ -1433,7 +1428,7 @@ else if (isset($grants) && $grants) {
|
||||
$tablegrant = stripslashes($tablegrant);
|
||||
}
|
||||
$result = mysql_query('SELECT * FROM mysql.tables_priv WHERE (Host = \'' . PMA_sqlAddslashes($host) . '\' OR Host = \'%\') AND (User = \'' . PMA_sqlAddslashes($pma_user) . '\' OR User = \'\') AND Db = \'' . PMA_sqlAddslashes($dbgrant) . '\' AND Table_name = \'' . PMA_sqlAddslashes($tablegrant) . '\'');
|
||||
$row = @mysql_fetch_array($result);
|
||||
$row = ($result) ? @mysql_fetch_array($result) : FALSE;
|
||||
if ($row && $row['Table_priv']) {
|
||||
while (list(,$priv) = each($list_priv)) {
|
||||
$priv_priv = $priv . '_priv';
|
||||
|
Reference in New Issue
Block a user