Skip to Main Content
Programming the Perl DBI
book

Programming the Perl DBI

by Tim Bunce, Alligator Descartes
February 2000
Intermediate to advanced content levelIntermediate to advanced
364 pages
11h 47m
English
O'Reilly Media, Inc.
Content preview from Programming the Perl DBI

And What About ADO?

ADO (ActiveX Data Objects) is Microsoft’s latest flavor of proprietary Win32-only data access API. They say “ADO is Microsoft’s strategic, high-level interface to all kinds of data.”

If it helps, you can think of ADO as a layer of gloss over ODBC, though in fact it’s built on Microsoft’s OLE DB API. ADO provides access to ODBC databases and also to many new data sources not previously available via ODBC. It’s object-oriented and designed to be easy to use, in theory.

You can use ADO from Perl via the Win32::OLE module. Here’s an example:

use Win32::OLE;
$conn = Win32::OLE->new("ADODB.Connection");
$conn->Open("DSN=MyDSN;UID=MyUID;PWD=MyPwd");
$RS = $conn->Execute("SELECT isbn, title FROM books");
if (!$RS) {
    $Errors = $conn->Errors();
    die "Errors:\n", map { "$_->{Description}\n" } keys %$Errors;
}

while ( !$RS->EOF ) {
    my ($isbn, $title) = (
        $RS->Fields('isbn')->Value,
        $RS->Fields('title')->Value,
    );
    print "$isbn : $title\n";
    $RS->MoveNext();
}
$RS->Close();
$conn->Close();

To save you from having to learn yet another data access API, the DBI comes to your rescue with DBD::ADO. The DBD::ADO driver lets you connect to any ADO data source and fetch data from it using portable DBI Perl code. There’s no need to learn a new API, and you’ll have a far easier life if you need to port applications to or from ADO.

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Advanced Perl Programming, 2nd Edition

Advanced Perl Programming, 2nd Edition

Simon Cozens
Perl One-Liners

Perl One-Liners

Peteris Krumins
Advanced Perl Programming

Advanced Perl Programming

Sriram Srinivasan
Beginning Perl

Beginning Perl

Curtis Ovid Poe

Publisher Resources

ISBN: 1565926994Supplemental ContentErrata Page