Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re: MS Access DB and WIN32::ODBC or ADO

by Eugene (Scribe)
on May 23, 2000 at 00:07 UTC ( [id://14283]=note: print w/replies, xml ) Need Help??


in reply to MS Access DB and WIN32::ODBC or ADO

Here is the code that I use to connect:

use Win32::ODBC; $DSN = "DRIVER=Microsoft Access Driver (*.mdb);FIL=MSAccess;DriverId=2 +5;DBQ=F:/webroot/Database/db1.mdb"; (this is the + actual location of your .mdb file)
Then you declare a new connection like
$db=new Win32::ODBC($DSN); and run a query: $db->Sql("SELECT * FROM Table"); $db->FetchRow(); %hash = $db->DataHash; $db->Close();

Replies are listed 'Best First'.
RE: Re: MS Access DB and WIN32::ODBC or ADO
by buzzcutbuddha (Chaplain) on May 23, 2000 at 16:33 UTC
    Ok, I don't know if you are going for portability, or if this will
    working off of one database for it's existence. If it is, you can
    set up an ODBC Connection for the database by using the ODBC icon in
    the Control Panel. This will take care of the DSN for you.

    I'll test out your code and see what errors I get back and let you know.
      i get the following error on my win2k system with the latest version of activestate:
      -==============-
      Can't call method "Sql" on an undefined value at cgi-bin lin e 8.
      -==============-
      i have the code written exactly as it is above, only changing the path to the .mdb file.

        Here's some more verbose code:

        use strict; use Win32::ODBC; my $DSN = "DRIVER=Microsoft Access Driver (*.mdb);FIL=MSAccess;DriverI +d=25;DBQ=c:\\my documents\\test.mdb"; my $db; my $query = "SELECT * FROM Books"; if (!($db = new Win32::ODBC($DSN))) { print "Error connecting to $DSN\n"; print "Error: " . Win32::ODBC::Error() . "\n"; } if( $db->Sql($query) ) { print "Error executing query [ \"$query\" ]\n"; print "Error: " . Win32::ODBC::Error() . "\n"; } # Debug stuff, to show return results: # $db->DumpData(); while( $db->FetchRow() ) { my %fields = $db->DataHash; print "$fields{'BookID'}: $fields{'Book Title'}\n"; } $db->Close();
        I reckon if you added error checking like this, you'd find that you're getting an error connecting to your datasource, and hopefully enough information to solve your problem?

        PS: I'd reccomend you create a user account here, and log on with it, as you then get notified when people answer you at logon.

        --
        RatArsed

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://14283]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others sharing their wisdom with the Monastery: (4)
As of 2024-04-19 13:52 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found