php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #51041 mysql_affected_rows() doesn't count rows affected through CASCADE foreign keys
Submitted: 2010-02-13 02:20 UTC Modified: 2010-02-24 14:15 UTC
From: info at fedushin dot ru Assigned: abedford (profile)
Status: Closed Package: Documentation problem
PHP Version: Irrelevant OS:
Private report: No CVE-ID: None
 [2010-02-13 02:20 UTC] 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.

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2010-02-24 14:13 UTC] 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-24 14:15 UTC] abedford@php.net
Has been fixed in XML sources.
 
PHP Copyright © 2001-2026 The PHP Group
All rights reserved.
Last updated: Wed Oct 07 23:00:01 2026 UTC