prepare()
$sth=$dbh->prepare(statement[, \%attr])
This function creates a statement handle by preparing an SQL
statement given as the first argument for subsequent execution with
execute(). It returns a reference to the
statement handle. The second argument is a hash of attributes and is
optional. A prepared statement or a statement handle may be used
multiple times until the disconnect() is
issued or until the statement handle value is overwritten by another
call to prepare() for the same statement
handle variable. More than one statement handle can be prepared if
different variables are used for storing the handle references. Here
is an example:
my $dbh = DBI->connect ("$dsn","$user","$pwd")
my $sql_stmnt = "SELECT title, author FROM books";
my $sth = $dbh->prepare($sql_stmnt, {RaiseError => 1, ChopBlanks => 1});Warning messages are enabled here and trailing spaces of fixed-width character columns are trimmed. See the end of this chapter for a list of attributes.