my $dbh = DBI->connect('foo', 'bar', 'baz', 'mysql')
or die "Can't connect: ", $DBI::errstr;
$dbh->{RaiseError} = 1;
####
my $sth = $dbh->prepare("select id from foo")
or die "Can't prepare: ", $dbh->errstr;
$sth->execute
or die "Can't execute: ", $dbh->errstr;
##
##
select id, name, phone from people
##
##
my($id, $name, $phone);
$sth->bind_columns(undef, \$id, \$name, \$phone);
##
##
while ($sth->fetch) {
print join("\t", $id, $name, $phone), "\n";
}
##
##
# Connect to the database and set the RaiseError
# attribute so that any database error will
# cause a die
my $dbh = DBI->connect('foo', 'bar', 'baz', 'mysql')
or die "Can't connect: ", $DBI::errstr;
$dbh->{RaiseError} = 1;
# Setup our statement handle using a placeholder
my $sth = $dbh->prepare_cached(<bind_columns(undef, \$id, \$name, \$phone);
for my $month (@months) {
print "People born in $month:\n";
# Execute the statement for this $month
$sth->execute($month);
# Fetch each row and print out the values
while ($sth->fetch) {
print "\t", join("\t", $id, $name, $phone), "\n";
}
}
$sth->finish;
$dbh->disconnect;
##
##
use Apache::DBI;
##
##
use DBI;