#!C:/Perl/bin/perl -w
use DBI;
my $DIR_PATH = 'C:/Perl/';
my $DBASE_NM = 'AccessDB.accdb';
my $PRI_TABLE_NM = "EMPLOYEE";
my $SEC_TABLE_NM = "AGE";
my $dsn = 'dbi:ODBC:driver=Microsoft Access Driver (*.mdb, *.accdb);dbq=' . $DIR_PATH . $DBASE_NM;
my $dbh = DBI->connect($dsn,undef,undef) || die "Can't reach database: $DBI::errstr";
my $sql= "SELECT PTN.EMPLOYEE_ID, PTN.EMPLOYEE_NM,
STN.EMPLOYEE_AGE, STN.EMPLOYEE_GNDR
FROM $PRI_TABLE_NM PTN INNER JOIN $SEC_TABLE_NM STN
ON PTN.EMPLOYEE_ID = STN.EMPLOYEE_ID";
$sth = $dbh->prepare($sql);
$sth->execute || die "Could not execute SQL statement: $!";
my $COL_NM = join(',', @{$sth->{NAME_lc}});
print "$COL_NM\n";
while (@row=$sth->fetchrow_array)
{
print join(",", @row), "\n";
}
$sth->finish;
$dbh->disconnect;
No comments :
Post a Comment