rows affected not working..

Discussion in 'Perl Misc' started by Faith Greenwood, Aug 11, 2009.

  1. Hi,

    I am making some changes to my mysql table via DBI (I am inserting the
    ages of the people I already have in the table). I have the following:

    my $sql="UPDATE table SET age=? WHERE name=?";
    my $sth=$dbh->prepare($sql);
    $sth->execute($age,$name) or warn "$DBI::errstr\n" and next;
    my $rc = $sth->rows;

    I have 100 records total. Of course, when I run this script the first
    time I update the age column of every single person in the table and
    $rc=1 for each of the 100 rows. However, running the script the 2nd
    time (without changing any of the ages), I still get $rc=1 for each of
    the 100 rows (it should be zero, since the row actually wasn't
    updated).

    To check, I updated a record via phpmyadmin and got 0 rows affected
    (like it should). Why is Perl giving me the wrong response? More
    importantly, how do I correct it?

    thx!
     
    Faith Greenwood, Aug 11, 2009
    #1
    1. Advertising

  2. Faith Greenwood

    Peter Wyzl Guest

    "Faith Greenwood" <> wrote in message
    news:...
    > Hi,
    >
    > I am making some changes to my mysql table via DBI (I am inserting the
    > ages of the people I already have in the table). I have the following:
    >
    > my $sql="UPDATE table SET age=? WHERE name=?";
    > my $sth=$dbh->prepare($sql);
    > $sth->execute($age,$name) or warn "$DBI::errstr\n" and next;
    > my $rc = $sth->rows;
    >
    > I have 100 records total. Of course, when I run this script the first
    > time I update the age column of every single person in the table and
    > $rc=1 for each of the 100 rows. However, running the script the 2nd
    > time (without changing any of the ages), I still get $rc=1 for each of
    > the 100 rows (it should be zero, since the row actually wasn't
    > updated).
    >
    > To check, I updated a record via phpmyadmin and got 0 rows affected
    > (like it should). Why is Perl giving me the wrong response? More
    > importantly, how do I correct it?


    If you are using DBD::mysql (usually invoked by use DBI and defining the
    mysql database) you should check the value of mysql_client_found_rows
    (check the DBD::mysql docs at
    http://search.cpan.org/~capttofu/DBD-mysql-4.012/lib/DBD/mysql.pm)

    I suspect you may have it set to TRUE but be expecting the result from
    having it set to FALSE.

    I could also be completely off the planet...

    P
     
    Peter Wyzl, Aug 11, 2009
    #2
    1. Advertising

  3. On Aug 11, 8:56 am, "Peter Wyzl" <> wrote:
    > "Faith Greenwood" <> wrote in message
    >
    > news:...
    >
    >
    >
    > > Hi,

    >
    > > I am making some changes to my mysql table via DBI (I am inserting the
    > > ages of the people I already have in the table). I have the following:

    >
    > > my $sql="UPDATE table SET age=? WHERE name=?";
    > > my $sth=$dbh->prepare($sql);
    > > $sth->execute($age,$name) or warn "$DBI::errstr\n" and next;
    > > my $rc = $sth->rows;

    >
    > > I have 100 records total. Of course, when I run this script the first
    > > time I update the age column of every single person in the table and
    > > $rc=1 for each of the 100 rows. However, running the script the 2nd
    > > time (without changing any of the ages), I still get $rc=1 for each of
    > > the 100 rows (it should be zero, since the row actually wasn't
    > > updated).

    >
    > > To check, I updated a record via phpmyadmin and got 0 rows affected
    > > (like it should). Why is Perl giving me the wrong response? More
    > > importantly, how do I correct it?

    >
    > If you are using DBD::mysql (usually invoked by use DBI and defining the
    > mysql database) you should check the value of mysql_client_found_rows
    > (check the DBD::mysql docs athttp://search.cpan.org/~capttofu/DBD-mysql-4..012/lib/DBD/mysql.pm)
    >
    > I suspect you may have it set to TRUE but be expecting the result from
    > having it set to FALSE.
    >
    > I could also be completely off the planet...
    >
    > P


    thanks guys! I think I will go with $sql="UPDATE table SET age=? WHERE
    name=? AND age!=?" as suggested...I just am looking for something that
    will alert me when the age has changed and this seems to work and to
    be honest I am too tired of this project to really care at this point
    so I'll just go with the easiest solution. At some point I will look
    more into the client_found_rows...;)....thx again!
     
    Faith Greenwood, Aug 12, 2009
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?QWw=?=

    Animated GIF affected by location.replace

    =?Utf-8?B?QWw=?=, Oct 12, 2004, in forum: ASP .Net
    Replies:
    3
    Views:
    7,305
    =?Utf-8?B?QWw=?=
    Oct 21, 2004
  2. Usama Alameldin

    which cotrols can be affected by viewstate

    Usama Alameldin, Jan 4, 2005, in forum: ASP .Net
    Replies:
    2
    Views:
    371
    Saravana
    Jan 4, 2005
  3. =?Utf-8?B?TXJGZXo=?=

    window.opener property affected by IE caching settings

    =?Utf-8?B?TXJGZXo=?=, Apr 28, 2005, in forum: ASP .Net
    Replies:
    7
    Views:
    602
    Kevin Spencer
    May 6, 2005
  4. Carl K

    mysql "rows affected"

    Carl K, Apr 27, 2007, in forum: Python
    Replies:
    4
    Views:
    6,318
    Carl K
    Apr 29, 2007
  5. Kushal Kumaran
    Replies:
    0
    Views:
    833
    Kushal Kumaran
    Nov 30, 2010
Loading...

Share This Page