Book HomeProgramming the Perl DBISearch this book

7.8. 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.



Library Navigation Links

Copyright © 2001 O'Reilly & Associates. All rights reserved.