Doc #60770 [Com]: Add Note to Documentation
| From: | david_colter at me dot com | Date: | Wed, 02 May 2012 14:28:49 +0000 |
| Subject: | Doc #60770 [Com]: Add Note to Documentation | ||
| References: | 1 | Groups: | php.doc.bugs |
| Request: | Send a blank email to doc-bugs+get-8329@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=60770&edit=1
ID: 60770
Comment by: david_colter at me dot com
Reported by: david_colter at me dot com
Summary: Add Note to Documentation
Status: Assigned
Type: Documentation Problem
Package: Documentation problem
Operating System: Linux
PHP Version: Irrelevant
Assigned To: philip
Block user comment: N
Private report: N
New Comment:
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.
Previous Comments:
------------------------------------------------------------------------
[2012-05-02 07:19:26] 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-01-16 14:57:33] 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
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=60770&edit=1