my ($dbh); sub Connect { $dbh = DBI->connect('DBI:ODBC:sybase_timallen','foo','bar') or die "Couldn't connect to database: " . DBI->errstr; $dbh->{LongReadLen} = 20000; } sub IS4_SQL_execute { #accept the SQL, then a list containing the bind values my $sql = shift; my @bind_values = @_; my $sth; #statement handle $sth = $dbh->prepare_cached($sql); $sth->execute(@bind_values) or die "Couldn't execute statement: " . $sth->errstr; return ($sth); # I count on the calling sub finishing the statement # and disconnecting } sub Disconnect { $dbh->disconnect(); } # -- Do your stuff now Connect(); my $sql = 'SELECT count(*) FROM products WHERE nr = ?'; my ($sth) = IS4_SQL_execute($sql,$nr); while (my @data = $sth->fetchrow_array()) { $count = $data[0]; } $sth->finish(); Disconnect();