#!/perl/bin/perl # # Sample Perl program that accesses an ODBC database # The DSN is hard coded to the name "eiw". use Win32::ODBC; # Set the name of the data source $DSN = "eiw"; # try to open the data source if (!($db = new Win32::ODBC($DSN))){ print "Error connecting to $DSN\n"; print "Error: " . Win32::ODBC::Error() . "\n"; exit; } # Read all the rows from the password table $SqlStatement = "SELECT * FROM password"; if ($db->Sql($SqlStatement)){ print "SQL failed.\n"; print "Error: " . $db->Error() . "\n"; $db->Close(); exit; } printf("Here are the field names found\n"); @FieldNames = $db->FieldNames(); printf("%s\n",join(" ",@FieldNames)); print "\n"; printf("Here is everything\n"); $db->Sql("SELECT Name, Password FROM password"); if ($db->Sql($SqlStatement)){ print "SQL failed.\n"; print "Error: " . $db->Error() . "\n"; $db->Close(); exit; } while ($db->FetchRow()) { ($n,$p)=$db->Data(); printf("REC: $n: $p\n"); } printf("Enter Name:\n"); chomp($name=<>); printf("Enter Password:\n"); chomp($password=<>); printf("adding the new name ($name) and password ($password)\n"); $sql = "INSERT INTO password (Name, Password) VALUES ('$name', '$password');"; if ($db->Sql($sql)) { print "Insert Failed\n"; print "Error: " . $db->Error() . "\n"; $db->Close(); exit; } print "Success\n"; $db->Close();