Do you have a question? Post it now! No Registration Necessary. Now with pictures!
- Posted on
- mysql_affected_rows() alternative
- Tyno Gendo
April 10, 2007, 2:04 pm
rate this thread
When i perform UPDATEs in my admin system, I'm checking for success by
using mysql_affected_rows() and this works fine if data is changed and
However, if a user submits an admin page without chaning any details,
the SQL executes fine, but mysql_affected_rows() returns 0 as MySQL is
clever enough to work out that nothing changed.
How do people deal with this? It hampers my error check as
mysql_affected_rows() can be 0 for a perfectly valid update.
Re: mysql_affected_rows() alternative
In addition to the other good answers: MySQL does have a mode where you can
override the "optimised" no-changes update, and actually give you the number
matching the WHERE clause rather than those changed.
The C API says to pass CLIENT_FOUND_ROWS when connecting, to change the
behaviour of mysql_affected_rows(). Looking at the PHP manual, it appears that
this flag may not yet be supported.
However, I've not looked further than the manual, so it may still be worth
digging through the API and possibly raising this as a feature request on:
Andy Hassall :: email@example.com :: http://www.andyh.co.uk
http://www.andyhsoftware.co.uk/space :: disk and FTP usage analysis tool