Solved

CGI script to access database info and email it.

Posted on 2002-06-03
4
156 Views
Last Modified: 2013-12-25
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
0
Comment
Question by:CUTTHEMUSIC
  • 2
  • 2
4 Comments
 
LVL 15

Expert Comment

by:samri
ID: 7053094
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.
0
 
LVL 15

Accepted Solution

by:
samri earned 200 total points
ID: 7053184
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.
0
 
LVL 12

Expert Comment

by:lexxwern
ID: 7053664
#!/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..
0
 
LVL 12

Expert Comment

by:lexxwern
ID: 7077305
CUTTHEMUSIC, are you here?
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The following is a collection of cases for strange behaviour when using advanced techniques in DOS batch files. You should have some basic experience in batch "programming", as I'm assuming some knowledge and not further explain the basics. For some…
In this tutorial I will show you how to provide a dynamic RTF document on your website generated with data from your database. For this tutorial you will need Microsoft Word or WordPad, WhizBase and Microsoft Access. In this tutorial I will show …
Learn the basics of strings in Python: declaration, operations, indices, and slicing. Strings are declared with quotations; for example: s = "string": Strings are immutable.: Strings may be concatenated or multiplied using the addition and multiplic…
The viewer will learn how to count occurrences of each item in an array.

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

26 Experts available now in Live!

Get 1:1 Help Now