Let the DBI cache your handles
Sometimes it's not easy to hold all your handles
- e.g., library code to lookup values from the database
-
The prepare_cached() method gives you a client side statement handle cache:
sub lookup_foo {
my ($dbh, $id) = @_;
$sth = $dbh->prepare_cached("select foo from table where id=?");
return $dbh->selectrow_array($sth, $id);
}
Can avoid the need for global statement handle variables