in reply to DBI performance problem
If you are feeling more ambitious, put these functions in a library that exported all the functions and the '$dbh' database handle. Exporter makes this really easy.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();
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: DBI performance problem
by dkubb (Deacon) on Jan 25, 2001 at 12:46 UTC | |
|
Re: Re: DBI performance problem
by zeno (Friar) on Jan 24, 2001 at 19:13 UTC | |
by Fastolfe (Vicar) on Jan 24, 2001 at 20:13 UTC | |
by zeno (Friar) on Jan 24, 2001 at 22:03 UTC |