I'm looking for information on the Win32::ODBC module for Perl 5.x but so far have run into problems using the module to display results from a SQL Fetch command. Does anyone know of any good documentation on this module?
looks quite good. A relavent bit is:
How do I use Win32::ODBC?
Others have put out some examples of using Win32::ODBC and it's use as a CGI script...
"Accessing ODBC Data Sources Through the Web" (by Zack Steinkamp <zsteinka@polymail.cpunix.calpoly.edu>).
A full discussion of ODBC is outside the scope of this FAQ but let's outline some basics.
First you need to create a DSN (Data Source Name) which is a name that represents the database file (or connection) and ODBC driver as well as user id and password.
Second you add the following USE line to the beginning of your Perl script:
use Win32::ODBC;
Third you open a connection to your database with (note that this example checks for failure):
$DSN = "My DSN";
if (!($db = new Win32::ODBC($DSN))){
print "Error connecting to $DSN\n";
print "Error: " . Win32::ODBC::Error() . "\n";
exit;
}
Fourth you execute your SQL command (NOTE: due to backward compatibility with NT::ODBC the Sql() method returns undef if it was successful and a non zero integer error number if it fails):
$SqlStatement = "SELECT * FROM Foo";
if ($db->Sql($SqlStatement)){
print "SQL failed.\n";
print "Error: " . $db->Error() . "\n";
$db->Close();
exit;
}
Fifth you fetch the next row of data until there are no more left to fetch. For each row you retrieve data and process it:
while($db->FetchRow()){
undef %Data;
%Data = $db->DataHash();
...process the data...
}
Sixth you close the connection to the database:
$db->Close();
That is it! Oh, so easy!
Is that similar to what you are doing? Mike
michael.j.lacey@ntlworld.com
Email welcome if you're in a hurry or something -- but post in tek-tips as well please, and I will post my reply here as well.
I'm going to assume that if I use the standard $key and $val to extract the data from the hash that is created when running the fetch, I should be fine. Is this a correct statement?
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.