467,146 Members | 1,021 Online
Bytes | Developer Community
Ask Question

Home New Posts Topics Members FAQ

Post your question to a community of 467,146 developers. It's quick & easy.

perl fork( ) doubt

I tried a small example in perl forking.
I opena connection with sql database in the parent or main program as follws:

Expand|Select|Wrap|Line Numbers
  1. $dbh = DBI->connect("DBI:mysql:database=$database;host=$host", $user, $pass) || die "\nDB connection error!\n";
And I try to execute some mql commands and it works fine.

As one of the process will take more time to finish, I open a fork as follows. And I try to do some sql commands inside the child process as below:

Expand|Select|Wrap|Line Numbers
  1.  $pid = fork();
  2. if( $pid == 0 ){
  3. $sth = $dbh->prepare("update $table SET STATUS=0 where CONFIGID=$id");
  4.  $sth->execute(); 
  5. }
But I get an error message as below:
Expand|Select|Wrap|Line Numbers
  1. DBD::mysql::st execute failed: MySQL server has gone away at test.pl line 172.
Do I have to open the database connection again inside the child process? I also tried using
Expand|Select|Wrap|Line Numbers
  1. $dbh->{'mysql_auto_reconnect'} = 1;
but I get the same error. Please let me know.

Thanks and Regards
Jul 23 '08 #1
  • viewed: 1534

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

31 posts views Thread by surfunbear@yahoo.com | last post: by
1 post views Thread by sm00thcrimnl13 | last post: by
1 post views Thread by Babu | last post: by
82 posts views Thread by Edward Elliott | last post: by
21 posts views Thread by anshul1806@gmail.com | last post: by
2 posts views Thread by sandhya2006 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.