The alternatives: Microsoft
## note that you'll need to define the ODBC connection separately
$dbh = new Win32::ODBC ("cms");
unless ($dbh->Sql("SELECT * FROM foo")) {
while ($dbh->FetchRow()) {
for my $field ($dbh->FieldNames()) {
print $field, " ", $dbh->Data($field), "\n";
}
}
}
- You can't have more than one query going at once.
- The full connection syntax is even more horrible than this.
## The Perl Way:
$dbh = DBI->connect('dbi:Oracle:sid,'user','pass');
$sth = $dbh->prepare("SELECT * FROM foo");
$sth->execute();
while ($hr = $sth->fetchrow_hashref()) {
for my $field (keys %$hr) {
print $field, " ", $hr->{$field}, "\n";
}
}
- Don't need to use "machine data sources" (can't!).
- Native perlish structures are returned.
- Alternatives to hashref exist -- array, arrayref, etc.