cvs: php4 /pear/DB mysql.php /pear/DB/tests/mysql 008.phpt
| From: | Stig Bakken | Date: | Fri, 08 Dec 2000 00:24:29 +0000 |
| Subject: | cvs: php4 /pear/DB mysql.php /pear/DB/tests/mysql 008.phpt | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-3019@lists.php.net to get a copy of this message | ||
ssb Thu Dec 7 16:24:29 2000 EDT
Modified files:
/php4/pear/DB mysql.php
/php4/pear/DB/tests/mysql 008.phpt
Log:
* change affectedRows semantics for MySQL: only return non-0 for
INSERT/UPDATE/DELETE queries
Index: php4/pear/DB/mysql.php
diff -u php4/pear/DB/mysql.php:1.33 php4/pear/DB/mysql.php:1.34
--- php4/pear/DB/mysql.php:1.33 Thu Dec 7 11:53:27 2000
+++ php4/pear/DB/mysql.php Thu Dec 7 16:24:28 2000
@@ -360,19 +360,20 @@
/**
* Gets the number of rows affected by the data manipulation
- * query. The behaviour of this function is undefined for SELECT
- * and other retrieval queries (such as SHOW).
+ * query. For other queries, this function returns 0.
*
* @return number of rows affected by the last query
*/
function affectedRows()
{
- $result = mysql_affected_rows($this->connection);
-
+ if (preg_match('/(INSERT|UPDATE|DELETE)/i', $this->last_query)) {
+ $result = mysql_affected_rows($this->connection);
+ } else {
+ $result = 0;
+ }
// [Sebastian]: Do we need to perform checks on $result here?
// [Stig]: Nope, but it will be 0 for "DELETE FROM table".
// Can't really think of a way to get around that though.
-
return $result;
}
Index: php4/pear/DB/tests/mysql/008.phpt
diff -u php4/pear/DB/tests/mysql/008.phpt:1.1 php4/pear/DB/tests/mysql/008.phpt:1.2
--- php4/pear/DB/tests/mysql/008.phpt:1.1 Thu Dec 7 11:53:27 2000
+++ php4/pear/DB/tests/mysql/008.phpt Thu Dec 7 16:24:28 2000
@@ -20,6 +20,6 @@
?>
--EXPECT--
1 after insert
-3 after select
+0 after select
2 after delete
0 after delete all