Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Execute query in fork

by manoj_speed (Priest)
on Apr 06, 2009 at 05:57 UTC ( #755641=perlquestion: print w/ replies, xml ) Need Help??
manoj_speed has asked for the wisdom of the Perl Monks concerning the following question:

I executed the following code.
use strict; use warnings; use DBI; my $DSN = 'dbi:Pg:dbname=manojkumar'; my $username = 'manojkumar'; my $password = 'manojkumar'; my $TABLE_NAME = "fork_log"; my $DBH = DBI->connect($DSN,$username,$password); if(fork()==0) { my $result = "insert into $TABLE_NAME(method) values('Child Su +ccess');"; if($DBH->do("$result")) { my $result = "insert into query_log(message) values('Q +uery success in fork child.');"; } else { my $result = "insert into query_log(message) values('Q +uery failed in fork child.');"; } exit; } wait(); my $result = "insert into $TABLE_NAME(method) values('Parent Success') +;"; my $STH = $DBH->do("$result");

In the above code, child process inserting values into the fork_log table and it is working fine. But in the parent the query is not executing and printing the following error.

DBD::Pg::db do failed: server closed the connection unexpectedly This probably means the server terminated abnormally before or while processing the request.

Why it is printing the above error and how can I solve this?

Comment on Execute query in fork
Select or Download Code
Re: Execute query in fork
by lakshmananindia (Chaplain) on Apr 06, 2009 at 05:59 UTC

    Refer InactiveDestroy in man DBI

    In general it is not a good practice to share the DBI connections between processes.

    I also suggest you to refer Can process Share DBI

    --Lakshmanan G.

    The great pleasure in my life is doing what people say you cannot do.


Re: Execute query in fork
by kyle (Abbot) on Apr 06, 2009 at 12:14 UTC

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://755641]
Approved by ELISHEVA
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (5)
As of 2014-08-30 21:53 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (294 votes), past polls