Re: Interesting problem
Available news archives: comp.lang.tcl - comp.lang.python - comp.security.firewalls - sci.crypt - comp.lang.php - comp.lang.javascript
Google
 
Web news.hping.org


comp.lang.php archive

Re: Interesting problem

From: Andy Hassall <andy@andyh.co.uk>
Date: Wed Mar 01 2006 - 21:34:00 CET

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
Received on Mon May 1 02:25:06 2006