sachaer has asked for the wisdom of the Perl Monks concerning the following question:
Thanks.--------------------------- mail program -------------- myquery ('3933'); #this is parent process $| = 1; # turn off buffering $newpid = fork(); if ( not defined $newpid ){ # if return value of fork() is undef, something went wrong die "fork didn't work: $!\n"; } elsif ( $newpid == 0 ){ # This is what the child process does print "inside child---------\n"; myquery ('3934'); exit( 0 ); } myquery ('3932'); ----------------one subroutine--------------------- sub myquery { my ($target_member_id) = @_; my ($query) = "select username from member where id=$target_member +_id"; my ($sth) = $mypackage::dbh->prepare ($query); $sth-> execute; my ($row) = $sth->fetchrow_array; if($row) { print "row: $row\n"; } else { print "empty\n"; } $sth->finish; } ---------------the perl module to establish the db connection ------ package mypackage; use DBI; $dbh = DBI->connect("$DB_SERVER:$DB_NAME;$DB_HOST",$DB_USERNAME,$DB_PA +SSWORD) || die "Content-type: text/html\n\nCan't connect to $dbname: $DBI::errstr\n"; ... ...
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Access the same database in two processes
by lestrrat (Deacon) on Oct 18, 2002 at 00:59 UTC | |
|
Re: Access the same database in two processes
by adrianh (Chancellor) on Oct 17, 2002 at 23:41 UTC |