use connect_cached so we will reconnect when mysql drops connection
[virtual-ldap] / lib / LDAP / Koha.pm
index 28d0868..540d278 100644 (file)
@@ -39,13 +39,11 @@ $SIG{__DIE__} = sub {
 
 require 'config.pl' if -e 'config.pl';
 
-my $dbh = DBI->connect($dsn . $database, $user,$passwd, { RaiseError => 1, AutoCommit => 1 }) || die $DBI::errstr;
-
 # we need reverse LDAP -> SQL mapping for where clause
 
 my $ldap_sql_mapping = {
        'uid'           => 'userid',
-       'objectGUID'    => 'borrowernumber',
+       'objectGUID'    => 'b.borrowernumber',
        'displayName'   => 'surname',
        'sn'            => 'surname',
        'pager'         => 'a.attribute',       # was: rfid_sid
@@ -208,6 +206,7 @@ sub search {
                        ;
 
                warn "# SQL:\n$sql\n# DATA: ",dump( @values );
+               my $dbh = DBI->connect_cached($dsn . $database, $user,$passwd, { RaiseError => 1, AutoCommit => 1 }) || die $DBI::errstr;
                my $sth = $dbh->prepare( $sql );
                $sth->execute( @values );