mysql_affected_rows() alternative

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Tyno Gendo

    mysql_affected_rows() alternative

    Two questions in a row.. I'm on a roll :)

    When i perform UPDATEs in my admin system, I'm checking for success by
    using mysql_affected_ rows() and this works fine if data is changed and
    updated.

    However, if a user submits an admin page without chaning any details,
    the SQL executes fine, but mysql_affected_ rows() returns 0 as MySQL is
    clever enough to work out that nothing changed.

    How do people deal with this? It hampers my error check as
    mysql_affected_ rows() can be 0 for a perfectly valid update.
  • Arjen

    #2
    Re: mysql_affected_ rows() alternative

    Tyno Gendo schreef:
    Two questions in a row.. I'm on a roll :)
    >
    When i perform UPDATEs in my admin system, I'm checking for success by
    using mysql_affected_ rows() and this works fine if data is changed and
    updated.
    >
    However, if a user submits an admin page without chaning any details,
    the SQL executes fine, but mysql_affected_ rows() returns 0 as MySQL is
    clever enough to work out that nothing changed.
    >
    How do people deal with this? It hampers my error check as
    mysql_affected_ rows() can be 0 for a perfectly valid update.
    Wrong and .. wrong. There is no perfectly valid update and you are not
    checking for errors :-)

    Add a field time(timestamp) and update "... time = NOW(), ... etc"

    --
    Arjen
    http://www.hondenpage.com - Mijn site over honden

    Comment

    • Tyno Gendo

      #3
      Re: mysql_affected_ rows() alternative

      Arjen wrote:
      Wrong and .. wrong. There is no perfectly valid update and you are not
      checking for errors :-)
      >
      Add a field time(timestamp) and update "... time = NOW(), ... etc"
      >
      Good idea, then there is always at least a time update. I like. Thanks
      Arjen.

      Comment

      • ZeldorBlat

        #4
        Re: mysql_affected_ rows() alternative

        On Apr 10, 10:04 am, Tyno Gendo <you@localhostw rote:
        Two questions in a row.. I'm on a roll :)
        >
        When i perform UPDATEs in my admin system, I'm checking for success by
        using mysql_affected_ rows() and this works fine if data is changed and
        updated.
        >
        However, if a user submits an admin page without chaning any details,
        the SQL executes fine, but mysql_affected_ rows() returns 0 as MySQL is
        clever enough to work out that nothing changed.
        >
        How do people deal with this? It hampers my error check as
        mysql_affected_ rows() can be 0 for a perfectly valid update.
        >From the manual at <http://www.php.net/mysql_query>
        "For other type of SQL statements, UPDATE, DELETE, DROP, etc,
        mysql_query() returns TRUE on success or FALSE on error."

        So check the return value of mysql_query(), not the value of
        mysql_affected_ rows().

        Comment

        • Tyno Gendo

          #5
          Re: mysql_affected_ rows() alternative

          ZeldorBlat wrote:
          "For other type of SQL statements, UPDATE, DELETE, DROP, etc,
          mysql_query() returns TRUE on success or FALSE on error."
          >
          So check the return value of mysql_query(), not the value of
          mysql_affected_ rows().
          >
          Thanks ZeldorBlat, that's what I was looking for. DATETIME thing Arjen
          suggested is good but I figured I was probably missing something very
          simple.

          Comment

          • Andy Hassall

            #6
            Re: mysql_affected_ rows() alternative

            On Tue, 10 Apr 2007 15:04:12 +0100, Tyno Gendo <you@localhostw rote:
            >Two questions in a row.. I'm on a roll :)
            >
            >When i perform UPDATEs in my admin system, I'm checking for success by
            >using mysql_affected_ rows() and this works fine if data is changed and
            >updated.
            >
            >However, if a user submits an admin page without chaning any details,
            >the SQL executes fine, but mysql_affected_ rows() returns 0 as MySQL is
            >clever enough to work out that nothing changed.
            >
            >How do people deal with this? It hampers my error check as
            >mysql_affected _rows() can be 0 for a perfectly valid update.
            In addition to the other good answers: MySQL does have a mode where you can
            override the "optimised" no-changes update, and actually give you the number
            matching the WHERE clause rather than those changed.

            The C API says to pass CLIENT_FOUND_RO WS when connecting, to change the
            behaviour of mysql_affected_ rows(). Looking at the PHP manual, it appears that
            this flag may not yet be supported.



            However, I've not looked further than the manual, so it may still be worth
            digging through the API and possibly raising this as a feature request on:


            Andy Hassall :: andy@andyh.co.u k :: http://www.andyh.co.uk
            http://www.andyhsoftware.co.uk/space :: disk and FTP usage analysis tool

            Comment

            Working...