perl fork( ) doubt

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • lilly07
    New Member
    • Jul 2008
    • 89

    #1

    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:

    Code:
    $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:

    Code:
     $pid = fork();
    if( $pid == 0 ){
    $sth = $dbh->prepare("update $table SET STATUS=0 where CONFIGID=$id");
     $sth->execute(); 
    }
    But I get an error message as below:
    Code:
    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
    Code:
    $dbh->{'mysql_auto_reconnect'} = 1;
    but I get the same error. Please let me know.

    Thanks and Regards
Working...