clone4 has asked for the wisdom of the Perl Monks concerning the following question:
(I cut down the code, so only the relevant pieces are included... Thanks for any help clone4#!/usr/bin/perl use Net::DNS; use DBI; use 5.10.0; use threads; use threads::shared; use Date::Calc qw(Delta_Days); use Net::DNS::Sendmail; use DBIx::Threaded; #use diagnostics; $| = 1; my $thread_no = shift; my $host = "localhost"; my $database = "test"; my $user = "root"; my $password = ""; my (@date) = (localtime)[5,4,3]; $date[1]++; $date[0] += 1900; my $dbh_t = DBIx::Threaded->connect("DBI:mysql:database=$database;host +=$host", $user, $password); DBIx::Threaded->dbix_threaded_create_pool(10); my $dbh = DBI->connect("DBI:mysql:database=$database;host=$host", $use +r, $password); my $sth = $dbh->prepare("SELECT id,domain,DATE(created) FROM domain_li +st"); $sth->execute(); my $counter = 0; while (my @row = $sth->fetchrow_array()) { my $id = $row[0]; my $domain = $row[1]; my $created = $row[2]; next unless $row[0..3]; my $thr = threads->create(mx_lookup,$id,$domain,$created) unless $ +counter >= $thread_no; $thr->detach && $counter++ if $thr; } $dbh_t->close_all(); $dbh->disconnect(); sub mx_lookup { my $id = shift; my $domain = shift; my $date_c = shift; my @date_c = split /-/, $date_c; my $delta = Delta_Days(@date_c,@date); if ($delta <= 30) { my $sth = $dbh_t->dbix_threaded_start_prepare("select max(id),domain_i +d,changed_from,changed_to,date from mx_history where domain_id=$id"); #this is where the script fails $sth->dbix_threaded_start(); my @row = $sth->fetchrow_array(); my $last_mx = $row[3]; $sth->finish(); } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Threads and multiple DBI connections
by BrowserUk (Patriarch) on Nov 01, 2010 at 16:30 UTC | |
by clone4 (Sexton) on Nov 01, 2010 at 17:06 UTC | |
by BrowserUk (Patriarch) on Nov 01, 2010 at 18:03 UTC | |
by clone4 (Sexton) on Nov 01, 2010 at 20:22 UTC | |
by BrowserUk (Patriarch) on Nov 01, 2010 at 22:02 UTC | |
|