As these treads are run, their subroutines pickup tasks to be processed then simply exit. My guess is while one $dbh is executing, another is called and when the first is finished, its no longer assigned to the same handle and thus crashes. Now here is the second part to my question... Is there a better way to use perl DBI when making multiple queries rather than constantly creating more than one $dbh? For example, when executing one query and data needs to be pulled from a second table, rather than creating $dbh2...? Here's some of the code contained in sql.pl used in the processing of queries.use DBI; use threads qw(stringify); use threads::shared; use Time::HiRes qw (sleep); do("./sql.pl"); &sql_setup; $server_id = "A"; share($server_id); $sys_ok = 1; share($sys_ok); $|++; $thr1 = threads->new(\&starter); $thr1->detach; $thr2 = threads->new(\&stopper); $thr2->detach; $thr3 = threads->new(\&monitor); $thr3->detach; $thr4 = threads->new(\&processor); $thr4->detach;
So to sum up two questions: 1. Is there a thread safe DBI or way to use DBI within multiple threads and processes? 2. Is there a better way to run a query inside a query without having to pre-define $dbh1 $dbh2 $dbh3? Thank you for your help and hope to hear from you soon.sub row_sql(){ my $select = $_[0]; my @row2,$dbh2,$sth2; if ($select eq ""){print "Empty Select."; exit;} $dbh2=DBI->connect($connectionInfo,$user,$passwd) || print "DBI Conn +ection Failed!($DBI::errstr)"; $sth2=$dbh2->prepare($select); if (!($sth2->execute())) { } @row2=$sth2->fetchrow_array(); $sth2->finish; $dbh2->disconnect(); return (@row2); }
In reply to Threads, MySQL & Ease of use by expresspotato
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |