note 33509 added to function.mysql-affected-rows

From: Date: Sat, 28 Jun 2003 04:47:55 +0000
Subject: note 33509 added to function.mysql-affected-rows
Groups: php.notes 
Request: Send a blank email to php-notes+get-51126@lists.php.net to get a copy of this message
"Note: When using UPDATE, MySQL will not update columns where the new value is the same as the old value. This creates the possiblity that mysql_affected_rows() may not actually equal the number of rows matched, only the number of rows that were literally affected by the query." As of PHP 4.3.0 (I assume, I only tried with 4.3.2), you can make mysql_affected_rows() return the number of rows matched, even if none are updated. You do this by setting the CLIENT_FOUND_ROWS flag in mysql_connect(). For some reason, not all the flags are defined in PHP, but you can use the decimal equivalent, which for CLIENT_FOUND_ROWS is 2. So, for example: $db= mysql_connect("localhost", "user", "pass", false, 2); mysql_select_db("mydb", $db); $query= "UPDATE ..."; mysql_query($query); print mysql_affected_rows(); // more than 0 mysql_query($query); // same query twice print mysql_affected_rows(); // still more than 0 ---- Manual Page -- http://www.php.net/manual/en/function.mysql-affected-rows.php Edit Note -- http://master.php.net/manage/user-notes.php?action=edit+33509 Delete Note -- http://master.php.net/manage/user-notes.php?action=delete+33509&report=yes Reject Note -- http://master.php.net/manage/user-notes.php?action=reject+33509&report=yes

« previous php.notes (#51126) next »