I tried a small example in perl forking.
I opena connection with sql database in the parent or main program as follws:
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:
But I get an error message as below:
Do I have to open the database connection again inside the child process? I also tried using
but I get the same error. Please let me know.
Thanks and Regards
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";
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();
}
Code:
DBD::mysql::st execute failed: MySQL server has gone away at test.pl line 172.
Code:
$dbh->{'mysql_auto_reconnect'} = 1;
Thanks and Regards