in reply to Writing to a DB in Windows Perl
#!/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();
|
|---|