Page 1 of 1

How do I know if my update statement was successful

Posted: Mon Oct 10, 2005 7:23 am
by Antek_Ryu
Hi All

How do I know if my update statement was successful when updating my database using php. I am working with php5 and mysql


Regards
Antek

Posted: Mon Oct 10, 2005 7:31 am
by malcolmboston

Posted: Mon Oct 10, 2005 8:03 am
by Weirdan
malcolmboston wrote:mysql_affected_rows
update statement could be successful without any rows being updated, for example:

Code: Select all

update table set column=123 where 2<1
would never update any rows, but it would succeed always (provided that `table` exists and there's `column` column in it)

Posted: Mon Oct 10, 2005 8:06 am
by Jenk
Well for a start, mysql_query() will not return false.. that proves it was a 'successful' statement, and mysql_affected_rows() returns how many rows were updated, this proving the criteria was correct/incorrect.

Using a bit of common sense you can work out if the intended results match the actual results..

Posted: Mon Oct 10, 2005 8:06 am
by Nathaniel

Code: Select all

mysql_query("UPDATE `table` SET `forks` = 4 WHERE `forks` < 4") or die("An error occurred");