improved the way the mysql_affected_rows is used
This commit is contained in:
11
ChangeLog
11
ChangeLog
@@ -6,9 +6,9 @@ $Id$
|
|||||||
$Source$
|
$Source$
|
||||||
|
|
||||||
2001-08-20 Olivier M<>ller <om@omnis.ch>
|
2001-08-20 Olivier M<>ller <om@omnis.ch>
|
||||||
* db_stats.php3: new file and feature (sorry :) : simply display
|
* db_stats.php3: new file and feature (sorry :) : simply display an
|
||||||
an overview of all databases with their respective size + server total.
|
overview of all databases with their respective size + server total.
|
||||||
* lang/*: new string $strDatabasesStats
|
* lang/*: new string $strDatabasesStats.
|
||||||
|
|
||||||
2001-08-20 Marc Delisle <lem9@users.sourceforge.net>
|
2001-08-20 Marc Delisle <lem9@users.sourceforge.net>
|
||||||
* config.inc.php3: $cfgProtectBlob is now TRUE by default, to help against
|
* config.inc.php3: $cfgProtectBlob is now TRUE by default, to help against
|
||||||
@@ -36,6 +36,7 @@ $Source$
|
|||||||
* lib.inc.php3, lines 266-277; config.lib.php3, lines 43, 57 & 70;
|
* lib.inc.php3, lines 266-277; config.lib.php3, lines 43, 57 & 70;
|
||||||
Documentation.html, lines 273-278 & 655-658: merged the socket patch from
|
Documentation.html, lines 273-278 & 655-658: merged the socket patch from
|
||||||
Dan Allen <bigredlinux@yahoo.com>.
|
Dan Allen <bigredlinux@yahoo.com>.
|
||||||
|
* sql.php3: improved the way the mysql_affected_rows is used.
|
||||||
|
|
||||||
2001-08-19 Olivier M<>ller <om@omnis.ch>
|
2001-08-19 Olivier M<>ller <om@omnis.ch>
|
||||||
* db_readdump.php3: if file contains mutiple queries, only show this line:
|
* db_readdump.php3: if file contains mutiple queries, only show this line:
|
||||||
@@ -53,7 +54,7 @@ $Source$
|
|||||||
* main.php3; db_details.php3; tbl_properties.php3; db_readdump.php3;
|
* main.php3; db_details.php3; tbl_properties.php3; db_readdump.php3;
|
||||||
lib.inc.php3: once a query has been executed phpMyAdmin now moves back
|
lib.inc.php3: once a query has been executed phpMyAdmin now moves back
|
||||||
to the calling script (rather than db_details.php3 everytime) as soon as
|
to the calling script (rather than db_details.php3 everytime) as soon as
|
||||||
the current database/table exists, else it moves back to a "parent"
|
the current database/table exists, else it moves back to a "parent"
|
||||||
script (the welcome page/'db_details.php3' if the current
|
script (the welcome page/'db_details.php3' if the current
|
||||||
database/table has has been dropped.
|
database/table has has been dropped.
|
||||||
* header.inc.php3, lines 63-64; sql.php3; db_details.php3;
|
* header.inc.php3, lines 63-64; sql.php3; db_details.php3;
|
||||||
@@ -61,7 +62,7 @@ $Source$
|
|||||||
to the calling script (and not the target one used only if this statement
|
to the calling script (and not the target one used only if this statement
|
||||||
is executed).
|
is executed).
|
||||||
* db_readdump.php3: improved Olivier's improvement for mutiple queries (see
|
* db_readdump.php3: improved Olivier's improvement for mutiple queries (see
|
||||||
before).
|
before).
|
||||||
* lib.inc.php3, line 524: beautify a bit the way the query is displayed.
|
* lib.inc.php3, line 524: beautify a bit the way the query is displayed.
|
||||||
* lang/english.inc.php3; lang/french.inc.php3: put $strInstructions at its
|
* lang/english.inc.php3; lang/french.inc.php3: put $strInstructions at its
|
||||||
right place.
|
right place.
|
||||||
|
46
sql.php3
46
sql.php3
@@ -59,12 +59,12 @@ if (isset($btnDrop) && $btnDrop == $strNo) {
|
|||||||
/**
|
/**
|
||||||
* Defines some "properties" of the sql query to submit
|
* Defines some "properties" of the sql query to submit
|
||||||
*/
|
*/
|
||||||
$do_confirm = ($cfgConfirm
|
$do_confirm = ($cfgConfirm
|
||||||
&& !isset($btnDrop)
|
&& !isset($btnDrop)
|
||||||
&& eregi('DROP +(TABLE|DATABASE)|ALTER TABLE +[[:alnum:]_`]* +DROP|DELETE FROM', $sql_query));
|
&& eregi('DROP +(TABLE|DATABASE)|ALTER TABLE +[[:alnum:]_`]* +DROP|DELETE FROM', $sql_query));
|
||||||
$is_select = eregi('^SELECT ', $sql_query);
|
$is_select = eregi('^SELECT ', $sql_query);
|
||||||
$is_count = ($is_select && eregi('^SELECT COUNT\((.*\.+)?\*\) FROM ', $sql_query));
|
$is_count = ($is_select && eregi('^SELECT COUNT\((.*\.+)?\*\) FROM ', $sql_query));
|
||||||
$is_delupd = eregi('^(DELETE|UPDATE) ', $sql_query);
|
$is_affected = eregi('^(DELETE|INSERT|LOAD DATA|UPDATE) ', $sql_query);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -109,7 +109,7 @@ else {
|
|||||||
$sql_query = stripslashes($sql_query);
|
$sql_query = stripslashes($sql_query);
|
||||||
}
|
}
|
||||||
|
|
||||||
//defines some variables
|
// Defines some variables
|
||||||
// loic1: A table have to be created -> left frame should be reloaded
|
// loic1: A table have to be created -> left frame should be reloaded
|
||||||
if (!empty($reload) && eregi('^CREATE TABLE (.*)', $sql_query)) {
|
if (!empty($reload) && eregi('^CREATE TABLE (.*)', $sql_query)) {
|
||||||
$reload = 'true';
|
$reload = 'true';
|
||||||
@@ -128,8 +128,23 @@ else {
|
|||||||
$full_sql_query = $sql_query . $sql_limit_to_append;
|
$full_sql_query = $sql_query . $sql_limit_to_append;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Executes the query
|
|
||||||
mysql_select_db($db);
|
mysql_select_db($db);
|
||||||
|
|
||||||
|
// If the query is a DELETE query with no WHERE clause, get the number of
|
||||||
|
// rows that will be deleted (mysql_affected_rows will always return 0 in
|
||||||
|
// this case)
|
||||||
|
if ($is_affected
|
||||||
|
&& eregi('^DELETE( .+)?( FROM (.+))$', $sql_query, $parts)
|
||||||
|
&& !eregi(' WHERE ', $parts[3])) {
|
||||||
|
$OPresult = @mysql_query('SELECT COUNT(*) as count' . $parts[2]);
|
||||||
|
if ($OPresult) {
|
||||||
|
$num_rows = mysql_result($OPresult, 0, 'count');
|
||||||
|
} else {
|
||||||
|
$num_rows = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Executes the query
|
||||||
$result = @mysql_query($full_sql_query);
|
$result = @mysql_query($full_sql_query);
|
||||||
|
|
||||||
// Displays an error message if required and stop parsing the script
|
// Displays an error message if required and stop parsing the script
|
||||||
@@ -139,9 +154,12 @@ else {
|
|||||||
mysql_die($error, $full_sql_query);
|
mysql_die($error, $full_sql_query);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Gets the number of rows returned ('@' is required because mysql_num_rows
|
// Gets the number of rows affected/returned
|
||||||
// ran on queries that are not 'SELECT' statements returns an error
|
if (!$is_affected) {
|
||||||
$num_rows = @mysql_num_rows($result);
|
$num_rows = @mysql_num_rows($result);
|
||||||
|
} else if (!isset($num_rows)) {
|
||||||
|
$num_rows = @mysql_affected_rows();
|
||||||
|
}
|
||||||
|
|
||||||
// Counts the total number of rows for the same 'SELECT' query without the
|
// Counts the total number of rows for the same 'SELECT' query without the
|
||||||
// 'LIMIT' clause that may have been programatically added
|
// 'LIMIT' clause that may have been programatically added
|
||||||
@@ -164,10 +182,10 @@ else {
|
|||||||
} // end rows total count
|
} // end rows total count
|
||||||
|
|
||||||
// No rows returned -> move back to the calling page
|
// No rows returned -> move back to the calling page
|
||||||
if ($num_rows < 1) {
|
if ($num_rows < 1 || $is_affected) {
|
||||||
if (file_exists('./' . $goto)) {
|
if (file_exists('./' . $goto)) {
|
||||||
if ($is_delupd) {
|
if ($is_affected) {
|
||||||
$message = $strAffectedRows . ' ' . mysql_affected_rows();
|
$message = $strAffectedRows . ' ' . $num_rows;
|
||||||
} else if (!empty($zero_rows)) {
|
} else if (!empty($zero_rows)) {
|
||||||
$message = $zero_rows;
|
$message = $zero_rows;
|
||||||
} else {
|
} else {
|
||||||
|
Reference in New Issue
Block a user