You are here: Re: Interesting problem « PHP Programming Language « IT news, forums, messages
Re: Interesting problem

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]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация