mysql_affected_rows() returning 0 but shouldn't be...
Posted: Mon Jan 15, 2007 4:11 pm
I have a very simple UPDATE query that is working perfectly and updating certain entries in a db table... but for some reason, when I run a conditional with mysql_affected_rows() right after the query, it always returns 0 eventhough I know for a fact that it is updating records (actually changing things, not just applying the same data). Below is an example of my setup:
mysql_affected_rows() is returning zero everytime. id Records 1, 3, 5 and 9 have marker set to 'N' before the update (the above code is an example only, the id's are selected everytime always have marker set to 'N'), so it is certainly updating the records and the application is working perfectly... other than it keeps displaying the 'No records were updated' even though they were indeed updated.
Any idea what could be causing this? My code seems to be spot on but I can't seem to figure this out. Thanks for your help and guidance.
Code: Select all
# Now update the database for the following records:
$query = "UPDATE table1 SET marker='Y' WHERE id IN (1, 3, 5, 9)";
$result = @mysql_query($query) or trigger_error("Query: $query\n<br />MySQL Error: " . mysql_error());
if (mysql_affected_rows() == 0)
echo '<p>No records were updated</p>';Any idea what could be causing this? My code seems to be spot on but I can't seem to figure this out. Thanks for your help and guidance.