Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
No disrespect intended, but here's a cleaner version (same code as above, but within code tags).
use strict; use DBI; $| =1; my @sites; #This below can be changed to 'dbi:ODBC:<name>' #provided you have DBI::ODBC installed #I'm testing both, and have both installed #They "feel" fairly interchangable my $dbh = DBI->connect('dbi:ADO:Name', undef, undef, {PrintError => 1, + RaiseError => 1}); #The two lines below are for use with DBI::ODBC #with BLOB, aka MEMO fields with large amounts of data. #Look in the docs for the modules for more on them #$dbh->{LongReadLen} = 65534; #$dbh->{LongTruncOk} = 1; my $sth = $dbh->prepare('SELECT * FROM tbldata'); $sth->execute; #dump_results is very good for testing, #and even for simple apps -- you don't need to #loop the results, just print out $results #my $results = DBI::dump_results($sth); #One of the nice things about DBI is the wide #variety in gives you in retrieving data while (my $results = $sth->fetchrow_hashref) { push @sites, $results; } ==================================================== Now for the Win32::ODBC version -- less commentary, as it's a little l +ess flexiable, but more obvious (IMHO): use Win32::ODBC; my @rows; my $DSN = "Name"; if (!($db = new Win32::ODBC($DSN))){ print "error connecting to $DSN\n"; print "error: " . Win32::ODBC::Error() . "\n"; exit; } die qq(SQL failed: ), $db->Error(), qq(\n) if ($db->Sql("SELECT * FROM + tbldata")); while ($db->FetchRow()) { my %data = $db->DataHash(); push @rows, {%data}; }

In reply to RE: Re: Can I talk to an MS Access DB using Perl? by athomason
in thread Can I talk to an MS Access DB using Perl? by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others pondering the Monastery: (6)
As of 2024-04-19 12:23 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found