php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #28871 mysql_afftected_rows returns 0 even when updates record
Submitted: 2004-06-21 18:39 UTC Modified: 2004-07-07 14:06 UTC
From: nav at nc dot ru Assigned:
Status: Not a bug Package: MySQL related
PHP Version: 4.3.6 OS: Windows XP
Private report: No CVE-ID: None
 [2004-06-21 18:39 UTC] nav at nc dot ru
Description:
------------
I've got the problem similar to already reported here.

mysql_afftected_rows sometimes returns 0, sometimes 1. Although actually it does UPDATES the record. This query changes user login (password, e-mail) in the table "user" (see below. If it matters, MySQL is 3.23.53-max, Apache is 1.3.27):

Reproduce code:
---------------
mysql_query("UPDATE user SET ".$setRequest." WHERE login = '$userCurrentLogin' AND password = md5('$userCurrentPass')");
/* $setRequest is the string compiled conditionally, but I've just printed whole query string and it looked correct:

UPDATE user SET login = 'aaa' WHERE login = 'bbb' AND password = md5('ccc') */

$num = mysql_affected_rows();
if ($num == 0) $errorMsg = "Could not complete your request. Check the data";
else if ($num == -1) $errorMsg = "Database error. Try again later";
else $changeMsg = "Your data has been successfully changed";

Expected result:
----------------
Of course, I expect correct work of mysql_affected_rows :)

Actual result:
--------------
BUT the result ($num) is sometimes 0, sometimes 1, even if the record is actually updated.

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2004-06-22 00:47 UTC] iliaa@php.net
Maybe the data is unchanged, meaning that it already was 
what you were trying to change it to. 
 [2004-06-22 12:07 UTC] nav at nc dot ru
No, I carefully checked the record before and after UPDATE. It WAS changed. However, mysql_affected_rows returned 0.
 [2004-06-30 08:41 UTC] georg@php.net
Not enough information was provided for us to be able
to handle this bug. Please re-read the instructions at
http://bugs.php.net/how-to-report.php

If you can provide more information, feel free to add it
to this bug and change the status back to "Open".

Thank you for your interest in PHP.


Please provide a complete and reproducable testcase/script 
(including table definition and plain sql statements). 
 [2004-07-07 13:48 UTC] nav at nc dot ru
Btw, now I've discovered, that mysql_num_rows after SELECT query doesn't work either! Or, to be more precise, it works the same wrong way as mysql_affected_rows.

That's getting interesting...
 [2004-07-07 14:02 UTC] nav at nc dot ru
I suppose now, that somewhere the code works twice - I hardly believe it should be a bug in both functions. I will close the topic for now.
 [2004-07-07 14:06 UTC] tony2001@php.net
Not a bug -> bogus.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Wed Sep 18 20:01:27 2024 UTC