php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #60770 Add Note to Documentation
Submitted: 2012-01-16 14:57 UTC Modified: 2012-06-01 07:01 UTC
From: david_colter at me dot com Assigned: philip (profile)
Status: Closed Package: Documentation problem
PHP Version: Irrelevant OS: Linux
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: david_colter at me dot com
New email:
PHP Version: OS:

 

 [2012-01-16 14:57 UTC] david_colter at me dot com
Description:
------------
---
From manual page: http://www.php.net/function.mysql-affected-rows#refsect1-
function.mysql-affected-rows-returnvalues
---

The documentation for Return Values is missing one important Note.

It is possible for the return value to be '2' for Update or '1' for Insert, when 
using a query like:
"INSERT INTO table ( field_1, ... ) VALUES ( 'abc', ... ) ON DUPLICATE KEY UPDATE 
field_1 = 'abc', ... WHERE key_field = 12345"

Test script:
---------------
NA

Expected result:
----------------
NA

Actual result:
--------------
NA

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2012-05-02 07:19 UTC] uw@php.net
Philip, 

can you decide on it? In my eyes the documentation is clear enough, no change needed. Please close thebug report if you concur.


"Return Values

Returns the number of affected rows on success, and -1 if the last query failed.

If the last query was a DELETE query with no WHERE clause, all of the records will have been deleted from the table but this function will return zero with MySQL versions prior to 4.1.2.

When using UPDATE, MySQL will not update columns where the new value is the same as the old value. This creates the possibility 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.

The REPLACE statement first deletes the record with the same primary key and then inserts the new record. This function returns the number of deleted records plus the number of inserted records."
 [2012-05-02 07:19 UTC] uw@php.net
-Assigned To: +Assigned To: philip
 [2012-05-02 14:28 UTC] david_colter at me dot com
Thanks for looking at this. IMO, the INSERT ... ON DUPLICATE KEY UPDATE query is 
a special case. I needed to look pretty far to learn what return values: 1 or 2 
mean in this case. Shouldn't that be 'available' in the documentation. (Think 
about the noobies trying to read, follow, learn and understand the 
documentation.) 

Further, 'Returns the number of affected rows on success, and -1 if the last 
query failed.' is not true in this case. If 2 is returned by the query, it isn't 
the number of rows affected! Hence, a request for a 'Note'.

Suggested note: In the case of INSERT ... ON DUPLICATE KEY UPDATE query, the 
return value will be 1 if an insert was performed or 2 for an update of an 
existing row.
 [2012-06-01 07:01 UTC] philip@php.net
Automatic comment from SVN on behalf of philip
Revision: http://svn.php.net/viewvc/?view=revision&revision=325920
Log: Documented PHP Bug #60770 -- Return value for 'INSERT ... ON DUPLICATE KEY UPDATE' queries. Note stolen from david_colter at me dot com.
 [2012-06-01 07:01 UTC] philip@php.net
-Status: Assigned +Status: Closed
 [2012-06-01 07:01 UTC] philip@php.net
The documentation has been updated, thank you for the bug report and suggested 
fix (which, was for the most part, added to the documentation as is).
 
PHP Copyright © 2001-2026 The PHP Group
All rights reserved.
Last updated: Wed Oct 07 22:00:01 2026 UTC