Link to home
Start Free TrialLog in
Avatar of CUTTHEMUSIC
CUTTHEMUSIC

asked on

CGI script to access database info and email it.

I would like a CGI/Perl script that will pull data from a Access 2000 database and then create a text file and insert the data into it. Then the script will email the text file as an attatchment it to me. I have done this ASP already but would like to experiment with CGI. I have almost no experience with CGI/Perl
Avatar of samri
samri
Flag of Malaysia image

What OS and Webserver platform are you running anyway?  What is your Perl version?

To do such, you will need to;

1. Grab a copy of DBD::ODBC and DBI Perl module and have it installed on your system.

2. Configure ODBC Driver configured to the specified Access database that you need to connect to.

3. Next get your CGI code.  Make sure you had you CGI.pm module installed to enable the output to be "web-enabled"


--- sample code that will list all tables in some database.  Make sure you configure the ODBC connector to connect to that specified Acess Database.

---
#!c:\perl\bin\perl

use DBI;


 $dbh = DBI->connect('dbi:ODBC:RESKIT', 'user', 'password');

my @dbs = $dbh->tables();

foreach (@dbs) {
  print "== $_\n";
}
----------------

To see the usage of DBI modules, do a "perldoc DBI" from command prompt, it should give you the detailed description and some sample code that you could use.

good luck.
ASKER CERTIFIED SOLUTION
Avatar of samri
samri
Flag of Malaysia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
#!/usr/local/bin/perl -w

use DBI;
use warnings;


$dbh =
     DBI->connect ("DBI:mysql:database=...;host=...;port=...",$DBuser,$DBpass)
          or
     die $DBI::errstr;


$query = "select * ...";
$askquery = $dbh->prepare($query);

$getentry = $askquery->execute;




this is how to work with DBI..
CUTTHEMUSIC, are you here?