|
Posted by Andy Hassall on 03/01/06 22:34
On Wed, 01 Mar 2006 15:02:41 -0500, ward@ wrote:
>On 1 Mar 2006 11:33:23 -0800, "frizzle" <phpfrizzle@gmail.com> wrote:
>
>Thanks again for the helpo Frizzle.
>
>I believe it's this statement that is causing the error...
>
>if (mysql_affected_rows() == 1) { // If it ran OK.
>
>This is from...
>
>if (mysql_affected_rows() == 1) { // If it ran OK.
MySQL already checks if the updated values match the existing values, and you
get mysql_affected_rows == 0 if they all match.
mysql> insert into t values (1, 'test');
Query OK, 1 row affected (0.00 sec)
mysql> update t set c = 'test' where id = 1;
Query OK, 0 rows affected (0.00 sec)
Rows matched: 1 Changed: 0 Warnings: 0
mysql> update t set c = 'not test' where id = 1;
Query OK, 1 row affected (0.01 sec)
Rows matched: 1 Changed: 1 Warnings: 0
It's the "Changed:" count that makes it out to PHP.
Don't start doing it yourself by selecting and checking, as you just introduce
race conditions, and MySQL is already doing this for you anyway.
Do check for an actual error through, as in mysql_query() returning false;
_that_ should be flagged up with the error message.
--
Andy Hassall :: andy@andyh.co.uk :: http://www.andyh.co.uk
http://www.andyhsoftware.co.uk/space :: disk and FTP usage analysis tool
Navigation:
[Reply to this message]
|