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:, 'server', 'XXXXX') or die "Couldn't connect to remote database: " . DBI->errstr; my $sthUpdateBandwidth = $remotedbh->prepare('UPDATE users SET bandwidth=? WHERE address LIKE ?') or die "Couldn't prepare to update bandwidth: " . $remotedbh->errstr; my $sthGetOldBandwidth = $remotedbh->prepare('SELECT bandwidth FROM users WHERE address LIKE ?') or die "Couldn't prepare to get old bw: " . $remotedbh->errstr; $sthGetBandwidth->execute or die "Couldn't get bandwidth: " . $sthGetBandwidth->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; } }