ricmetal Posted July 10, 2011 Share Posted July 10, 2011 hi is there a way to differentiate between the MySqli affected_rows(), where no rows where found with WHERE, and no changes where made? the PHP manual says this: "Zero indicates that no records where updated for an UPDATE statement, no rows matched the WHERE clause in the query or that no query has yet been executed" regards Quote Link to comment https://forums.phpfreaks.com/topic/241599-diference-between-no-rows-found-with-where-and-no-changes-to-row/ Share on other sites More sharing options...
.josh Posted July 10, 2011 Share Posted July 10, 2011 Can you give more details? At face value, I think you're asking...if you have an update statement like update table set a=b where c=d You want to know which rows were matched in the c=d, but not actually updated? Well no...there is no way to find that out, because that's not how it works. All rows that match c=d will have a=b applied to it. "Zero indicates that no records where updated for an UPDATE statement, no rows matched the WHERE clause in the query or that no query has yet been executed" IOW, no rows matched, therefore nothing was updated. Quote Link to comment https://forums.phpfreaks.com/topic/241599-diference-between-no-rows-found-with-where-and-no-changes-to-row/#findComment-1240937 Share on other sites More sharing options...
ricmetal Posted July 10, 2011 Author Share Posted July 10, 2011 You want to know which rows were matched in the c=d, but not actually updated? yes. All rows that match c=d will have a=b applied to it. but if the value being updated is the same value that is already in the database, the affected_rows yields zero...so there should be a way to differentiate. Quote Link to comment https://forums.phpfreaks.com/topic/241599-diference-between-no-rows-found-with-where-and-no-changes-to-row/#findComment-1240940 Share on other sites More sharing options...
PFMaBiSmAd Posted July 10, 2011 Share Posted July 10, 2011 I'm not sure where you got that quote from in the documentation, but the only official information is - 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. To determine if the row was not affected due to the data being the same or the WHERE clause being false, you would need to fist execute a SELECT query with the same WHERE clause. You would then know that the matching row exists and the update returned a zero for mysql_affected_rows() because the data being updated is the same as the old value. Quote Link to comment https://forums.phpfreaks.com/topic/241599-diference-between-no-rows-found-with-where-and-no-changes-to-row/#findComment-1240941 Share on other sites More sharing options...
ricmetal Posted July 10, 2011 Author Share Posted July 10, 2011 To determine if the row was not affected due to the data being the same or the WHERE clause being false, you would need to fist execute a SELECT query with the same WHERE clause. You would then know that the matching row exists and the update returned a zero for mysql_affected_rows() because the data being updated is the same as the old value. thats what i thought after posting this thread.cheers Quote Link to comment https://forums.phpfreaks.com/topic/241599-diference-between-no-rows-found-with-where-and-no-changes-to-row/#findComment-1240942 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.