Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

MS-ACCESS/PERL/USE DBI

Status
Not open for further replies.

cicero777

Technical User
Mar 17, 2011
2
US
Hey there,

I hope this is not annoying as I've spend countless hours looking at others peoples code to get someething VERY basic to work which I've had no luck. To skip background and bullshit, see #5 below:
Background:
1) I am running strawberry perl v5.12.2 for MSWin32-x86
2) I want to do teh following use DBI;
3) recursive DOS search shows several DBI.PM installed which may or may not be found in the @INC array
C:\strawberry dir /s DBI*.pm

4) To summarize I probably have various DBI.pm floating around in
subdirectories -

When I reun this script via other programmers suggestions:

#!C:\strawberry\perl\bin\perl.exe


use Win32::OLE;
my $DBFile = qw(C:\Documents and Settings\Owner\Desktop\Drug_List.mdb); #
#Choose appropriate version of Jet for your system
my $Jet = Win32::OLE->CreateObject('DAO.DBEngine.36')
or die "Can't create Jet database engine.";
my $DB = $Jet->OpenDatabase($DBFile);
my $SQLquery = "SELECT * FROM Drug List";
$DB = $dbh->prepare($SQLquery);
my $DB->Execute($SQLquery, 128); #128=DBFailOnError

while (@row=$DB->fetchrow_array()) {
print "@row\n";}


I get the following error (less errors because I turned
off use strict; and use warnings;

"Can't call method prepare on an undefined value at accessproj.pl line 11


Can someone PLease help? I am running winxp, strawberry perl, downloaded dBI.pm not sure if @inc is finding it (I assume so),a nd just want to test to see if perl can open an access database and retrieve a simple SQL query. This would provide me great relief and joy! Thank you.

 
Here is a script that does work, i had to take out the propritary parts.

Code:
use DBI;
use strict;

my $dbh = DBI->connect('dbi:ODBC:driver=Microsoft Access Driver (*.mdb);dbq=D:\path\to\DB.mdb') or die "can't connect to DBI:$!\n";

my $sth = $dbh->prepare("select stuff from table");
$sth->execute or die $dbh->errstr;
while (my @data=$sth->fetchrow_array()){ 
   print "@data\n"; 
}
$dbh->disconnect;

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[noevil]
Travis - Those who say it cannot be done are usually interrupted by someone else doing it; Give the wrong symptoms, get the wrong solutions;
 
I want to thank Travis. A simple task in your opinion but it provided joy to me. I hope you may of service in the future or others of your expertise......Silence is one of the great arts of communication - Cicero 106 B.C.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top