I'm comfortable with DBI. I use it all the time. On local machines. The time has come to use DBI to update a database on a remote machine, and as far as I can tell it should really be working. Obviously it doesn't, otherwise it'd be no fun! Here's the code:
my $dbh = DBI->connect('DBI:mysql:psa', 'admin', 'XXXXX') or die "Couldn't connect to database: " . DBI->errstr; my $sthGetBandwidth = $dbh->prepare('SELECT domains.name, hosting.real +_traffic/1024/1024 FROM domains, hosting WHERE hosting.dom_id=domains +.id LIMIT 10') or die "Couldn't prepare to get bandwidth: " . $dbh->errstr; my $remotedbh = DBI->connect('DBI:mysql:all34SP:<IP address>, 'server' +, 'XXXXX') or die "Couldn't connect to remote database: " . DBI->errstr; my $sthUpdateBandwidth = $remotedbh->prepare('UPDATE users SET bandwid +th=? WHERE address LIKE ?') or die "Couldn't prepare to update bandwidth: " . $remotedbh-> +errstr; my $sthGetOldBandwidth = $remotedbh->prepare('SELECT bandwidth FROM us +ers WHERE address LIKE ?') or die "Couldn't prepare to get old bw: " . $remotedbh->errstr +; $sthGetBandwidth->execute or die "Couldn't get bandwidth: " . $sthGetB +andwidth->errstr; my @data; while (@data = $sthGetBandwidth->fetchrow_array()) { $sthGetOldBandwidth->execute($data[0]); unless ($sthGetOldBandwidth->rows == 0) { my @oldbw = $sthGetOldBandwidth->fetchrow_array(); my $newbw = sprintf '%.2f', $data[1]; print "Setting bandwidth for $data[0] to $newbw (was $ +oldbw[0])\n"; $sthUpdateBandwidth->execute($data[0], $newbw) or die "Couldn't update bandwidth for $data[0] +: " . $sthUpdateBandwidth->errstr; } }
Those of you in the know might recognize what I'm trying to do. I'm pulling bandwidth usage information from a database on the local machine and putting it into a database on a remote machine. Here's the output:
Setting bandwidth for napiersnowsports.com to 3.92 (was 0.00) Setting bandwidth for pc-helper.net to 6.02 (was 0.00) Setting bandwidth for leemajors.co.uk to 144.66 (was 0.00) Setting bandwidth for kamonohashi.net to 0.00 (was 0.00) Setting bandwidth for smszone.net to 1.35 (was 0.00) Setting bandwidth for ukundergraduate.com to 0.31 (was 0.00) Setting bandwidth for win2000b.34SP.com to 0.07 (was 0.00) Setting bandwidth for mettacattery.org to 8.30 (was 0.00) Setting bandwidth for interlink-wireless.com to 2.57 (was 0.00)
And on a second running:
Setting bandwidth for napiersnowsports.com to 3.92 (was 0.00) Setting bandwidth for pc-helper.net to 6.02 (was 0.00) Setting bandwidth for leemajors.co.uk to 144.66 (was 0.00) Setting bandwidth for kamonohashi.net to 0.00 (was 0.00) Setting bandwidth for smszone.net to 1.35 (was 0.00) Setting bandwidth for ukundergraduate.com to 0.31 (was 0.00) Setting bandwidth for win2000b.34SP.com to 0.07 (was 0.00) Setting bandwidth for mettacattery.org to 8.30 (was 0.00) Setting bandwidth for interlink-wireless.com to 2.57 (was 0.00)
So basically it's not getting updated. The zeroes for previous bandwidth are correct. If I change the value in the db, it does change there. And now to the question: Why isn't it updated?

In reply to DBI UPDATE statement failing by Merlin83

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.