my $dbh = DBIx::Threaded->connect("DBI:mysql:database=$database;host=$host", $user, $password); DBIx::Threaded->dbix_threaded_create_pool(10); my $sth = $dbh->prepare("SELECT id,domain,DATE(created) FROM domain_list"); $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,$dbh) unless $counter >= $thread_no; $thr->detach && $counter++ if $thr; } $sth->finish(); 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); my %emails_in; my %emails_out; if ($delta <= 30) { my @mx = mx($domain); #add multiple mxs support here my $mx_count = @mx; my $mx = $mx[0]->exchange; #find the last change for the given domain my $sth = $dbh->prepare("select max(id),domain_id,changed_from,changed_to,date from mx_history where domain_id=?"); #this is where the script fails $sth->execute($id); my @row = $sth->fetchrow_array(); $sth->finish(); } } #### Thread 43 terminated abnormally: Error:Unexpected db_prepare request: must be connected to do that.