php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #41325 mysqli_affected_rows() returns wrong value if warnings are raised
Submitted: 2007-05-08 14:50 UTC Modified: 2007-05-27 23:55 UTC
From: php-qa at sebastianmendel dot de Assigned:
Status: Closed Package: Documentation problem
PHP Version: 5.2.2 OS: Windows / Linux
Private report: No CVE-ID: None
 [2007-05-08 14:50 UTC] php-qa at sebastianmendel dot de
Description:
------------
issuing an insert statement that raises warnings mysqli_affected_rows() returns the warning count instead of inserted rows count

tested with MySQL server 5.0, 5.1 and 5.2 (6.0)

Reproduce code:
---------------
// open db connection/select db
//$mysqli = mysqli_...
// create table
$sql = 'CREATE TABLE `test` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `int` int(11) NOT NULL,
  `int2` int(11) NOT NULL,
  PRIMARY KEY (`id`)
)';
mysqli_query($mysqli, $sql);
// insert row
$sql = 'INSERT INTO `test` (`int`, `int2`) VALUES ('', '');'
mysqli_query($mysqli, $sql);

echo mysqli_affected_rows($mysqli);

Expected result:
----------------
1

Actual result:
--------------
2

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2007-05-08 15:07 UTC] scottmac@php.net
I can't reproduce this with 5.0.27. I get the expected output of 1.

Do you have any other sort of special configuration or setting?
 [2007-05-08 15:28 UTC] tony2001@php.net
Cannot reproduce on Linux with both client & server of version 5.0.26.
 [2007-05-08 17:17 UTC] php-qa at sebastianmendel dot de
ok, my fault, it is not a really a bug in mysqli_affected_rows() - it is more a documentation bug

the mysql c api function mysql_affected_rows returns not only for teh last INSERT, UPDATE, REPLACE or DELETE, but for SELECT too

"returns the number of rows changed (for) UPDATE), deleted (for DELETE, or inserted (for INSERT. For SELECT  statements, mysql_affected_rows() works like mysql_num_rows()."

http://dev.mysql.com/doc/refman/5.1/en/mysql-affected-rows.html

and mysqli_affected_rows() does it the same way, of course, but the php manual does read other

"Returns the number of rows affected by the last INSERT, UPDATE, REPLACE or DELETE query."

http://php.net/mysqli_affected_rows
 [2007-05-08 18:27 UTC] php-qa at sebastianmendel dot de
just to clarify: my test works as expected and not as i have written, SORRY!
 [2007-05-20 10:22 UTC] ljbuesch at purdue dot edu
From 1.20 to 1.21 the note:
--
For SELECT statements mysqli_affected_rows works like mysqli_num_rows.
--

Was removed with a commit note by didou:

--
Removed useless note
--

Should we re-add the note, or update the documents to reflect that this function does indeed work on select statements, as it is misleading to not mention it.
 [2007-05-20 13:56 UTC] philip@php.net
If the mysqli version of this indeed differs from its mysql brethren, then the mysqli documentation should be updated. Whether we mention this difference somewhere, not sure where, but at some point we'll want a "How to upgrade mysql to mysqli" document.

The user notes should never be used or thought of as a replacement for documentation. Any doc worthy information from them should be folded into the manual.


 [2007-05-27 23:55 UTC] ljbuesch@php.net
This bug has been fixed in the documentation's XML sources. Since the
online and downloadable versions of the documentation need some time
to get updated, we would like to ask you to be a bit patient.

Thank you for the report, and for helping us make our documentation better.

Restored old comment that was removed in 1.21.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Apr 23 10:01:29 2024 UTC