PERL 8
Access_db.pl Guest on 20th November 2020 05:29:47 AM
  1. #
  2. # Example of a connect and a trivial select using (gasp) DBI
  3. #
  4. # I have no idea why this works, but it does.
  5. # It connects up to an MSAccess db full of class and student info
  6. # Some dummy db that was created by the wizard for idiots like me (JA)
  7. #
  8. use strict;
  9. use DBI;
  10.  
  11. my $dbName = "dbi:ODBC:testDB";
  12. my $dbUserName = "eCAPEhacker";
  13. my $dbPassword = "guest";
  14.  
  15.  
  16. my $dbh = DBI->connect( $dbName,
  17.                         $dbUserName,
  18.                         $dbPassword )
  19.                         || die "Database connection refused: $DBI::errstr";
  20.  
  21. my $sql = qq{ SELECT * FROM CLASSES };
  22. my $sth = $dbh->prepare( $sql );
  23. $sth->execute();
  24.  
  25. my( $classId, $className, $deptId, $secNum,
  26.     $profId, $term, $units, $yr, $loc, $time, $notes );
  27.  
  28. $sth->bind_columns( undef, \$classId, \$className, \$deptId, \$secNum,
  29.                     \$profId, \$term, \$units, \$yr, \$loc, \$time, \$notes );
  30.  
  31. while ( $sth->fetch() )
  32. {
  33.         print "$classId, $className, $deptId, $time\n";
  34. }
  35.  
  36. $sth->finish();
  37. $dbh->disconnect();

Paste is for source code and general debugging text.

Login or Register to edit, delete and keep track of your pastes and more.

Raw Paste

Login or Register to edit or fork this paste. It's free.