Merlin83 has asked for the wisdom of the Perl Monks concerning the following question:
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: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; } }
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?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)
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: DBI UPDATE statement failing
by perrin (Chancellor) on Dec 14, 2001 at 22:42 UTC | |
by Merlin83 (Novice) on Dec 14, 2001 at 23:36 UTC | |
by perrin (Chancellor) on Dec 15, 2001 at 00:00 UTC | |
|
Re: DBI UPDATE statement failing
by cfreak (Chaplain) on Dec 15, 2001 at 00:40 UTC | |
|
Re: DBI UPDATE statement failing
by andye (Curate) on Dec 14, 2001 at 22:18 UTC | |
by Merlin83 (Novice) on Dec 14, 2001 at 22:27 UTC | |
by andye (Curate) on Dec 14, 2001 at 22:37 UTC | |
by Merlin83 (Novice) on Dec 14, 2001 at 22:39 UTC |