##
# Display a table in a database using PERL ODBC module
use Win32::ODBC;
$dsn = "testDB";
$table = "Main";
# ====== Check if the database can be opened correctly
if (!($db = new Win32::ODBC($dsn))) {
print "Error in opening DSN \"$dsn\"!\n";
print "Error: " . Win32::ODBC::Error(). "\n";
exit;
}
# ====== Select all fields from the given table
$sql = "select Date_time from Main where Date_Time >= DateAdd(\"h\", -2, '1/05/2008 05:35') ";
# ====== Check if the SQL query is correct
if ($db->Sql($sql)) {
print "Error in SQL query: \"$sql\"!\n";
print "Error: " . $db->Error() . "\n";
$db->Close();
exit;
}
# ====== Print field data
print "Content-type: text/html\n\n";
print "\n";
$count = 1;
@FieldNames = $db->FieldNames();
while ($db->FetchRow()) {
print "Record $count\n";
%Data = $db->DataHash();
foreach $x (@FieldNames) {
#print "$x: $Data{$x}\n";
print "$Data{$x} ";
}
print "\n";
$count++;
}
$db->Close();