#51041 [Asn->Csd]: mysql_affected_rows() doesn't count rows affected through CASCADE foreign keys

From: Date: Wed, 24 Feb 2010 14:15:18 +0000
Subject: #51041 [Asn->Csd]: mysql_affected_rows() doesn't count rows affected through CASCADE foreign keys
References: 1  Groups: php.doc.bugs 
Request: Send a blank email to doc-bugs+get-3970@lists.php.net to get a copy of this message
ID: 51041 Updated by: abedford@php.net Reported By: info at fedushin dot ru -Status: Assigned +Status: Closed Bug Type: Documentation problem PHP Version: Irrelevant Assigned To: abedford New Comment: Has been fixed in XML sources. Previous Comments: ------------------------------------------------------------------------ [2010-02-24 14:13:30] svn@php.net Automatic comment from SVN on behalf of abedford Revision: http://svn.php.net/viewvc/?view=revision&revision=295471 Log: Added note that mysql_affected_rows() does not count rows affacted by CASCADE. Fixes doc bug #51041 ------------------------------------------------------------------------ [2010-02-13 02:20:33] info at fedushin dot ru Description: ------------ It would be useful to document the following: mysql_affected_rows() DOES NOT count rows affected implicitly through 'ON DELETE CASCADE' and/or 'ON UPDATE CASCADE' foreign keys. Reproduce code: --------------- --- From manual page: function.mysql-affected-rows --- CREATE TABLE types ( type varchar(10) NOT NULL, PRIMARY KEY (type) ) ENGINE=InnoDB; CREATE TABLE symbols ( symbol char(1) NOT NULL, type varchar(10) NOT NULL, PRIMARY KEY (symbol), KEY FK_symbol_type (type) ) ENGINE=InnoDB; ALTER TABLE symbols ADD CONSTRAINT FK_symbol_type FOREIGN KEY (type) REFERENCES types (type) ON DELETE CASCADE ON UPDATE CASCADE; INSERT INTO types VALUES ('Number'), ('Letter'); INSERT INTO symbols VALUES ('1', 'Number'), ('2', 'Number'), ('A', 'Letter'), ('B', 'Letter'); <?php mysql_query('UPDATE types SET type = "Digit" WHERE type = "Number"'); echo mysql_affected_rows() . '<br>'; mysql_query('DELETE FROM types WHERE type = "Letter"'); echo mysql_affected_rows() . '<br>'; ?> Expected result: ---------------- Each query actually affects 3 rows (1 type + 2 symbols), but output is: 1 1 Actual result: -------------- That's OK, but needs to be documented. ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=51041&edit=1

« previous php.doc.bugs (#3970) next »