SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Enthusiast
    Join Date
    Mar 2007
    Posts
    83
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    MySQL update issue - matching but not updating

    I have an issue that when someone updates with the same information it will return with no affected rows, but on mysql_info() it says it's matched but not changed it.

    What function is there to check it's matched ? 'Cause even if it's matched, if it doesn't change (due to it being the same) then it will always come back 0 rows affected.

    A function like this would be a great help !

    Thanks : )

  2. #2
    Follow Me On Twitter: @djg gold trophysilver trophybronze trophy Dan Grossman's Avatar
    Join Date
    Aug 2000
    Location
    Philadephia, PA
    Posts
    20,578
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    There is no function since MySQL only provides the number of affected rows to the client. PHP can't get information MySQL doesn't give it. You'll need to do a SELECT query.

    If you want to forced affected rows, add an 'updated' column and give it the current date on each update.

  3. #3
    SitePoint Enthusiast
    Join Date
    Dec 2003
    Location
    Miami, FL
    Posts
    32
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi. I gather you might be using php5 (or a different version of mysql than I am accustomed to), because where I was submitting a duplicate of what was already there, it just came back "No changes made" or the like.

    So to do a prior check for duplication, I read the current info into a variable, and do an

    =

    if ( $whatever_it_was == $the_new_data ) {
    do not try to update
    } else {
    update the data
    }

    =

    I don't know if there is some function that could make this easier.

    I hope that is some help.

    Rich


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •