mysql_affected_rows() returning 0 but shouldn't be...

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
seodevhead
Forum Regular
Posts: 705
Joined: Sat Oct 08, 2005 8:18 pm
Location: Windermere, FL

mysql_affected_rows() returning 0 but shouldn't be...

Post by seodevhead »

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:

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>';
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.
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

Have you got more than one database connection open?
User avatar
seodevhead
Forum Regular
Posts: 705
Joined: Sat Oct 08, 2005 8:18 pm
Location: Windermere, FL

Post by seodevhead »

d11wtq wrote:Have you got more than one database connection open?
Nope... just one. It is really really odd.
Post Reply