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?!!"
|