CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
Search Posts SEARCH
Who's Online WHO'S
Log in LOG

Home: Need a Custom or Prewritten Perl Program?: I need a program that...:
Survey script to Access Database



Jun 16, 2000, 8:27 AM

Post #1 of 2 (2453 views)
Survey script to Access Database Can't Post

I have a survey script that post to a txt file. What I really want though is a survey script that posts directly to an Access database. If there is a way to get automatically from a txt file to an Access database, that would be a good intermediate solution.

Many thanks


User / Moderator

Jun 15, 2000, 10:25 PM

Post #2 of 2 (2453 views)
Re: Survey script to Access Database [In reply to] Can't Post

Use the DBI suite of modules.

DBD::ODBC can handle the Access portion, and you can use DBD::CSV or DBD::RAM for the text file.

Depending on your text, the latter's probably overkill as you could get away with something like ...

<BLOCKQUOTE><font size="1" face="Arial,Helvetica,sans serif">code:</font><HR>

use DBI;
my $dbh = DBI->connect("dbi:ODBC:MyAccessDB") &#0124; &#0124; die $DBI::errstr;
my $sth = $dbh->prepare("INSERT INTO tables VALUES (?,?,?,?)") &#0124; &#0124; die $dbh->errstr;

open TEXT, "MyTextDB.txt" &#0124; &#0124; die "Can't open MyTextDB.txt: $!";
while(<TEXT> ) {
my(@values) = split /,/, 4;
$sth->execute(@values) &#0124; &#0124; die $sth->errstr;

... which would populate your Access db assuming it's four fields corresponded to four comma seperated fields in your text file.

You can download DBI, DBD::ODBC, and DBD::CSV via ppm (if you use ActiveState's perl) or CPAN (if you use one of the other varieties).


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives