From b9bb61d45e47bd8c89710cc8026affcf33b688a8 Mon Sep 17 00:00:00 2001 From: Marc Delisle Date: Tue, 26 Nov 2002 17:57:06 +0000 Subject: [PATCH] bug 644108 --- ChangeLog | 3 +++ sql.php3 | 22 ++++++++++++++-------- 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/ChangeLog b/ChangeLog index 4a3ec109c..4f49b913b 100755 --- a/ChangeLog +++ b/ChangeLog @@ -5,6 +5,9 @@ phpMyAdmin - Changelog $Id$ $Source$ +2002-11-26 Marc Delisle + * sql.php3: bug 644108: incorrect affected rows count + 2002-11-25 Marc Delisle * tbl_properties_structure.php3: wrong back link in case of errors * sql.php3: undefined variable $sql_query when adding a bookmark diff --git a/sql.php3 b/sql.php3 index b7f11acef..fc649d16c 100755 --- a/sql.php3 +++ b/sql.php3 @@ -294,7 +294,9 @@ else { $num_rows = 0; } } - // Executes the query + + // E x e c u t e t h e q u e r y + // Only if we didn't ask to see the php code (mikebeck) if (!empty($GLOBALS['show_as_php']) || !empty($GLOBALS['validatequery'])) { unset($result); @@ -302,6 +304,7 @@ else { } else { $result = @PMA_mysql_query($full_sql_query); + // Displays an error message if required and stop parsing the script if (PMA_mysql_error()) { $error = PMA_mysql_error(); @@ -312,6 +315,16 @@ else { PMA_mysqlDie($error, $full_sql_query, '', $full_err_url); } + // Gets the number of rows affected/returned + // (This must be done immediately after the query because + // mysql_affected_rows() reports about the last query done) + + if (!$is_affected) { + $num_rows = ($result) ? @mysql_num_rows($result) : 0; + } else if (!isset($num_rows)) { + $num_rows = @mysql_affected_rows(); + } + // Checks if the current database has changed // This could happen if the user sends a query like "USE `database`;" $res = PMA_mysql_query('SELECT DATABASE() AS "db";'); @@ -330,13 +343,6 @@ else { unlink($textfile); } - // Gets the number of rows affected/returned - if (!$is_affected) { - $num_rows = ($result) ? @mysql_num_rows($result) : 0; - } else if (!isset($num_rows)) { - $num_rows = @mysql_affected_rows(); - } - // Counts the total number of rows for the same 'SELECT' query without the // 'LIMIT' clause that may have been programatically added if (empty($sql_limit_to_append)) {