HELP NEEDED - MySQL UPDATE query with zero affected rows
Posted: Tue Oct 26, 2004 1:02 pm
I just ran into this today and was wondering if someone can offer some assistance. I have a form (PHP 4+) that when processed runs an UPDATE to one table, then after it successfully completes the update, runs an UPDATE on another table. I have it set up in my database in a way that after the first update is done, it error checks using an IF-ELSE statement:
I did this to prevent the second table from being updated if the first table had problems. Now I have a new issue.
If there are no changes to the data used in the first UPDATE query, the script returns an affected row count of 0. When that happens, it runs the error script and does not update the second portion of data. My question is: how do you check your result to see if the first update had zero affected rows because the data did not change AND NOT because of an SQL error?
Any insight on this issue would be most appreciated. Up until today I had no idea that MySQL did not return an affected row count if the data in the UPDATE query did not change.
Code: Select all
<?php
$sql = "UPDATE ...";
if ( !$db->sql_query($sql) || !$db->sql_affectedrows())
{
//run error reporting
}
else
{
//run second update query
}
?>If there are no changes to the data used in the first UPDATE query, the script returns an affected row count of 0. When that happens, it runs the error script and does not update the second portion of data. My question is: how do you check your result to see if the first update had zero affected rows because the data did not change AND NOT because of an SQL error?
Any insight on this issue would be most appreciated. Up until today I had no idea that MySQL did not return an affected row count if the data in the UPDATE query did not change.