note 20910 added to function.mysql-affected-rows
| From: | ben-xo at NOSPAMdubplatesNOSPAM dot org | Date: | Sun, 21 Apr 2002 11:31:05 +0000 |
| Subject: | note 20910 added to function.mysql-affected-rows | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-29636@lists.php.net to get a copy of this message | ||
mysql_affected_rows() reports on the number of rows affected by an in-place operation on the
database, but mysql_num_rows() returns the number of rows in a MySQL record set (which is held by
PHP after MySQL has generated it). This means that if you can do
$a = mysql_query("SELECT ...");
$b = mysql_query("SELECT ...");
if (mysql_unm_rows($a) > mysql_num_rows($b)) print "a is larger";
else print "b is larger";
... but this does not make sense for the operations supported by mysql_affected_rows(), which
reports on the status of the database connection as a whole.
Particularly note this:
$query = "UPDATE ...";
mysql_query($query);
print mysql_affected_rows(); // more than 0
mysql_query($query); // same query twice
print mysql_affected_rows(); // 0.
.. this is because the 2nd time you execute the identical query, all the rows are already updated so
no rows are affected the 2nd time.
I hope this clears up why mysql_num_rows() and mysql_affected_rows() are fundamentally different
--
http://www.php.net/manual/en/function.mysql-affected-rows.php
http://master.php.net/manage/user-notes.php?action=edit+20910
http://master.php.net/manage/user-notes.php?action=delete+20910
http://master.php.net/manage/user-notes.php?action=reject+20910