By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,692 Members | 1,998 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,692 IT Pros & Developers. It's quick & easy.

perl fork( ) doubt

P: 89
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
Share this question for a faster answer!
Share on Google+

Post your reply

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