Serialize and deserialize perl DBI connection object

215 views Asked by At

I need serialize one array with DBI connection objects to shared with others process using shared memory. But deserialize not working.

use storable qw/freeze thaw/;

my @connections;

for(my $c = 0;$c < 5;$c++) {
  my $conn = DBI->connect($dsn,$user,$password,{'AutoCommit' => 1, 'RaiseError' => 1, 'PrintError' => 0});
  push(@connections,$conn);
}

my $shm = freeze(@connections);
my $obj = thaw($shm);

Return error: Global symbol

"$drh" requires explicit package name (did you forget to declare "my $drh"?) at (eval 33) line 6.

1

There are 1 answers

4
Steffen Ullrich On

You cannot serialize a database handle/connection since it consists of user space data not reachable by Storable (i.e. outside Perl and inside the database library and maybe also in the TLS library) and also kernel data like file descriptors.