mysql_affected_rows() question

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

    mysql_affected_rows() question

    Hi,

    I'm doing a table insert and have a question about mysql_affected_ rows().

    The following code works. It correctly inserts the row and
    mysql_affected_ rows() returns 1 as it should do.

    $sql = "INSERT INTO member (company, username, password, cookie,
    session, ip) VALUES ('$company', '$user', '$pass', 'fakecookie',
    'fakesession', '192.168.1.1')" ;

    $result = mysql_query($sq l) or MyDie("Error: ".mysql_error() );

    // Determine success:
    // mysql_affected_ rows returns the number of affected rows on
    // success, and -1 if the last query failed.

    $rowsAffected = mysql_affected_ rows();


    However the final line, the call to mysql_affected_ rows, used to have
    $result as an argument, like this:

    $rowsAffected = mysql_affected_ rows($result);

    Which as far as I can tell is correct. When I use that line, the row gets
    inserted correctly, but the call to mysql_affected_ rows() fails, with the
    following error message:

    "Warning: mysql_affected_ rows(): supplied argument is not a valid
    MySQL-Link resource in /home/fakeuser/public_html/test/adduser.php on line
    104"

    I don't understand why it is not a valid link resource. The almost
    identical code, but making a 'select' query and not doing an 'insert',
    works fine when checking with 'mysql_num_rows ($result)'.

    Obviously this is not critical, since I've got it working, but in the
    interests of increasing my understanding can someone explain this problem
    to me please.

    Many thanks.
  • Jonas Werres

    #2
    Re: mysql_affected_ rows() question

    "Warning: mysql_affected_ rows(): supplied argument is not a valid
    MySQL-Link resource in /home/fakeuser/public_html/test/adduser.php on
    line 104"
    PHP Manual:
    For SELECT, SHOW, DESCRIBE, EXPLAIN and other statements returning
    resultset, mysql_query() returns a resource on success, or FALSE on error.
    For other type of SQL statements, UPDATE, DELETE, DROP, etc,
    mysql_query() returns TRUE on success or FALSE on error.

    So: Because TRUE is not a Resource, which is expected.
    Ha, that was easy.

    Indeed, mysql_affected_ rows() does NOT expect the return value of
    mysql_query(), but the connection resource:


    So, to but it in a nutshell: RTFM!

    Comment

    • MS

      #3
      Re: mysql_affected_ rows() question

      Jonas Werres emailed this:
      >"Warning: mysql_affected_ rows(): supplied argument is not a valid
      >MySQL-Link resource in /home/fakeuser/public_html/test/adduser.php on
      >line 104"
      >
      PHP Manual:
      For SELECT, SHOW, DESCRIBE, EXPLAIN and other statements returning
      resultset, mysql_query() returns a resource on success, or FALSE on error.
      For other type of SQL statements, UPDATE, DELETE, DROP, etc,
      mysql_query() returns TRUE on success or FALSE on error.
      >
      So: Because TRUE is not a Resource, which is expected.
      Ha, that was easy.
      >
      Indeed, mysql_affected_ rows() does NOT expect the return value of
      mysql_query(), but the connection resource:

      >
      So, to but it in a nutshell: RTFM!
      Oh, I'm so sorry! I did RTFM, but *obviously* not very effectively.

      Thanks for the help.

      Feeling humbled and very sorry.

      Comment

      • Darko

        #4
        Re: mysql_affected_ rows() question

        On Nov 12, 8:15 pm, MS <No.Way.J...@No .Spam.Thank.You .comwrote:
        Jonas Werres emailed this:
        >
        >
        >
        "Warning: mysql_affected_ rows(): supplied argument is not a valid
        MySQL-Link resource in /home/fakeuser/public_html/test/adduser.php on
        line 104"
        >
        PHP Manual:
        For SELECT, SHOW, DESCRIBE, EXPLAIN and other statements returning
        resultset, mysql_query() returns a resource on success, or FALSE on error.
        For other type of SQL statements, UPDATE, DELETE, DROP, etc,
        mysql_query() returns TRUE on success or FALSE on error.
        >
        So: Because TRUE is not a Resource, which is expected.
        Ha, that was easy.
        >
        Indeed, mysql_affected_ rows() does NOT expect the return value of
        mysql_query(), but the connection resource:
        http://de2.php.net/manual/en/functio...ected-rows.php
        >
        So, to but it in a nutshell: RTFM!
        >
        Oh, I'm so sorry! I did RTFM, but *obviously* not very effectively.
        >
        Thanks for the help.
        >
        Feeling humbled and very sorry.
        Well, you shouldn't feel humbled and very sorry, but only sorry.
        Don't exaggerate :)

        Comment

        • MS

          #5
          Re: mysql_affected_ rows() question

          Darko emailed this:
          On Nov 12, 8:15 pm, MS <No.Way.J...@No .Spam.Thank.You .comwrote:
          >Jonas Werres emailed this:
          >>
          >>
          >>
          >>>"Warning: mysql_affected_ rows(): supplied argument is not a valid
          >>>MySQL-Link resource in /home/fakeuser/public_html/test/adduser.php on
          >>>line 104"
          >>PHP Manual:
          >>For SELECT, SHOW, DESCRIBE, EXPLAIN and other statements returning
          >>resultset, mysql_query() returns a resource on success, or FALSE on error.
          >>For other type of SQL statements, UPDATE, DELETE, DROP, etc,
          >>mysql_query () returns TRUE on success or FALSE on error.
          >>So: Because TRUE is not a Resource, which is expected.
          >>Ha, that was easy.
          >>Indeed, mysql_affected_ rows() does NOT expect the return value of
          >>mysql_query() , but the connection resource:
          >>http://de2.php.net/manual/en/functio...ected-rows.php
          >>So, to but it in a nutshell: RTFM!
          >Oh, I'm so sorry! I did RTFM, but *obviously* not very effectively.
          >>
          >Thanks for the help.
          >>
          >Feeling humbled and very sorry.
          >
          Well, you shouldn't feel humbled and very sorry, but only sorry.
          Don't exaggerate :)
          Ok, I take the humbled bit back. I'm just sorry. ;-)

          Comment

          • Jerry Stuckle

            #6
            Re: mysql_affected_ rows() question

            MS wrote:
            Jonas Werres emailed this:
            >>"Warning: mysql_affected_ rows(): supplied argument is not a valid
            >>MySQL-Link resource in /home/fakeuser/public_html/test/adduser.php on
            >>line 104"
            >>
            >PHP Manual:
            >For SELECT, SHOW, DESCRIBE, EXPLAIN and other statements returning
            >resultset, mysql_query() returns a resource on success, or FALSE on
            >error.
            >For other type of SQL statements, UPDATE, DELETE, DROP, etc,
            >mysql_query( ) returns TRUE on success or FALSE on error.
            >>
            >So: Because TRUE is not a Resource, which is expected.
            >Ha, that was easy.
            >>
            >Indeed, mysql_affected_ rows() does NOT expect the return value of
            >mysql_query( ), but the connection resource:
            >http://de2.php.net/manual/en/functio...ected-rows.php
            >>
            >So, to but it in a nutshell: RTFM!
            >
            Oh, I'm so sorry! I did RTFM, but *obviously* not very effectively.
            >
            Thanks for the help.
            >
            Feeling humbled and very sorry.
            >
            Don't worry about it. This area of mysql can be confusing. So many of
            the calls take a result from mysql_query(), and you would think that
            this one would, also.

            But alas, it's (one of) the exception(s) to the "rule". :-)

            --
            =============== ===
            Remove the "x" from my email address
            Jerry Stuckle
            JDS Computer Training Corp.
            jstucklex@attgl obal.net
            =============== ===

            Comment

            Working...