6 Einträge, 1 Seite |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#! c:\perl\bin\perl
use Win32::ODBC;
$DriverType = "Microsoft Access Driver (*.mdb)";
$DSN = "Win32 ODBC --MAOmaoMAOmaoMAO--";
$Dir = "c:\\meinOrdner";
$DBase = "meineDB.mdb";
Win32::ODBC::ConfigDSN(ODBC_ADD_DSN, $DriverType,("DSN=$DSN", "Description=MAO Win32 ODBC Test DSN for Perl", "DBQ=$Dir\\$DBase", "DEFAULTDIR=$Dir", "UID=", "PWD=")) or die "ConfigDSN(): Could not add temporary DSN" . Win32::ODBC::Error();
$db=new Win32::ODBC($DSN) or die "couldn't ODBC $DSN because ", Win32::ODBC::Error(), "\n";
$query = "select * from table1, table2 where table1.spalte = table2.spalte";
!$db->Sql($query) or die "couldn't do $query because ", $db->Error(), "\n";
while($db->FetchRow())
{
my %Data = $db->DataHash();
foreach my $key(keys(%Data)){
print $key," -> ",$Data{$key};
}
}
Win32::ODBC::ConfigDSN(ODBC_REMOVE_DSN, $DriverType, "DSN=$DSN") or die "ConfigDSN(): Could not remove temporary DSN because ", Win32::ODBC::Error();
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
use DBI;
#open connection to Access database
$dbh = DBI->connect('dbi:ODBC:driver=microsoft access driver (*.mdb);dbq=C:\Windows\Desktop\meineDB.mdb');
#prepare and execute SQL statement
$sqlstatement="SELECT * FROM table1, table2 WHERE table1.spalte = table2.spalte";
$sth = $dbh->prepare($sqlstatement);
$sth->execute ||
die "Could not execute SQL statement ... maybe invalid?";
#output database results
while (@row=$sth->fetchrow_array()){
print "@row\n";
}
6 Einträge, 1 Seite |