Win32::ODBC
The Win32::ODBC module was written by Dave Roth,
based on original code by Dan DeMaggio. It’s a Perl extension
written in C++ and is closely associated with the Win32 platform.
The main goal of the Win32::ODBC module is to
provide direct access to the ODBC functions. From that point of view,
Win32::ODBC provides a fairly thin, low-level
interface.
Here’s a sample of Win32::ODBC code:
use Win32::ODBC;
### Connect to a data source
$db = new Win32::ODBC("DSN=MyDataDSN;UID=me;PWD=secret")
or die Win32::ODBC::Error();
### Prepare and Execute a statement
if ($db->Sql("SELECT item, price FROM table")) {
print "SQL Error: " . $db->Error() . "\n";
$db->Close();
exit;
}
### Fetch row from data source
while ($db->FetchRow) {
my ($item, $price) = $db->Data(); ### Get data values from the row
print "Item $item = $price\n";
}
### Disconnect
$db->Close();The most significant disadvantages of
Win32::ODBC
compared to DBD::ODBC are:
- There is no separate statement handle
The database connection handle is used to store the details of the current statement. There is no separate statement handle, so only one statement can execute per database handle. But that’s not as bad as it may seem, because it’s possible to clone database handles so that more than one handle can share the same underlying ODBC database connection.
- There are no separate prepare and execute steps
You cannot prepare a statement for execution later. The
Sql()method, like the DBIdo()method, combines both.- Placeholders and ...