Jump to content

Recommended Posts

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

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.

 

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.

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.

 

 

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.