Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re: Writing to a DB in Windows Perl

by Mission (Hermit)
on Jun 28, 2001 at 17:09 UTC ( [id://92266]=note: print w/replies, xml ) Need Help??


in reply to Writing to a DB in Windows Perl

Fiji, the first answer is correct, but I'll explain a bit to get you started. First of all, we like to encourage people to try to help themselves first, it's better for everyone that way. When you get stuck, simply explain as much as you can (where you've searched for the answer, and what the error is) and make sure that you post code examples. This allows us to help you more efficiently (and accurately.)

First of all, you will need to install the DBI.pm and the DBD-ODBC.pm from CPAN. There are lots of documentation that comes with Perl and with the modules, so specific questions can usually be answered there. Here is a quick code example for hitting an Access DB locally.
#!/usr/bin/perl -w use strict; #Make sure you always use strict! use DBI; #This implements the DBI.pm # Connect to the Access database called 'db1.mdb' my $DSN = 'driver=Microsoft Access Driver (*.mdb);dbq=db1.mdb'; my $dbh = DBI->connect("dbi:ODBC:$DSN") || die "Couldn't open database +: $DBI::errstr; stopped"; # Prepare the SQL query for execution # From the TEST_TBL return all values for FIELD1,FIELD2,FIELD3 my $SQL1 = $dbh->prepare(<<End_SQL) || die "Couldn't prepare statement +: $DBI::errstr; stopped"; select FIELD1, FIELD2, FIELD3 FROM TEST_TBL End_SQL # Execute the query $SQL1->execute() || die "Couldn't execute statement: $DBI::errstr; sto +pped"; # Fetch each row and print it while ( my ($field1, $field2, $field3) = $SQL1->fetchrow_array() ) { print "Found: $field1 - $field2 - $field3"; } # Disconnect from the database $dbh->disconnect();


Fiji, I suggest that you get an account here at Perl Monks and participate. It will help you learn more about Perl, and it's a good community to participate with. Good luck.

- Mission
"Heck I don't know how to do it either, but do you think that's going to stop me?!!"

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others examining the Monastery: (7)
As of 2024-04-24 00:54 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found