#!/usr/bin/perl use DBI; use strict; # connect to the database, using mysql in example my $dbh = DBI->connect("DBI:mysql:dbname:hostname", "user", "pass") or die "Couldn't Connect: $DBI::errstr"; # prepare statement handle $sth = $dbh->prepare("SELECT * FROM table WHERE field = ?); # ? is a placeholder that can be filled when execute is called $sth->execute($val_of_field) or die "Error: $DBI::errstr"; # $DBI::errstr stores the error string returned by the DB while (@vals = $sth->fetchrow->array()) { # do stuff # do more stuff } $sth->finish(); #close statement handle $dbh->disconnect(); #disconnect