Forum Moderators: coopster

Message Too Old, No Replies

mysql_affected_rows()

not sure about it

         

henry0

1:57 pm on Feb 4, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I am trying to check if any data in any existing row/rows was updated ( not checkng for new row)

so I try using the mysql_affected_rows(),
however regardless of updates within an existing row
it keeps showing "no updates" (I know updates were passed)

I simplyfied the echo wordings but the skeleton script is the same

$num = mysql_affected_rows($sql, $conn);

if ($num == 0) {

echo "<p>No update yet!</p>";

} else {

echo $num;
echo "<p>Updated!</p>";

}

Thank you

mincklerstraat

2:24 pm on Feb 4, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



you might try dropping the arguments when you call the function, just simply:
mysql_affected_rows()

When you use an argument, it needs to be the 'link identifier' handler. This is just a single variable, not two like you've got - just a modest suggestion, I haven't used this function so I can't give you detailed info. Also, have you tried doing this with error_reporting(E_ALL)? It might give you some info if there's something wrong.

henry0

3:37 pm on Feb 4, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Thanks it works
but I figured that it does not fit my expectations

I forgot about an "updated field"
so even if no updates are performed
it will always show "updated" for when submited even without modif the updated time will change

so I think that I should do a "isset" against each other updatable fields
but it is a long task (about 60 fields)

any way to shorten my quest?

thanks

dreamcatcher

6:08 pm on Feb 4, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Try something like:

if (mysql_affected_rows()==0)
{

//nothing updated

}

henry0

6:47 pm on Feb 4, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Thank you
It still shows "updated" due to the updated field

I guess that threre is no short cut

I will use "isset" to check each field

regards

coopster

7:34 pm on Feb 5, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



henry0, you aren't using transaction-based (COMMIT) processing are you? If not you should be OK. From the mysql_affected_rows() manual page...


When using UPDATE, MySQL will not update columns where the new value is the same as the old value. This creates the possibility that mysql_affected_rows() may not actually equal the number of rows matched, only the number of rows that were literally affected by the query.

henry0

9:27 pm on Feb 5, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



No "COMMIT" Here!

This is exactly what I was thinking when I used the ()
as per my top script

Plus I also looked at the manual and got reinforced in my decision to use the function

I know it should work and not show "updated"

well I guess I will play more with it

thanks

henry