Solved

DBI & CGI

Posted on 2000-02-26
3
185 Views
Last Modified: 2013-12-25
where can I learn more about CGI.pl and DBI.pl (I think this is what they are called).
0
Comment
Question by:evildogeye
3 Comments
 
LVL 3

Expert Comment

by:monas
Comment Utility
perldoc CGI

and

perldoc DBI

are command you want to issue...
0
 
LVL 10

Accepted Solution

by:
makerp earned 50 total points
Comment Utility
if your running activeperl on win32 both modules are well docuemented in the help which youll find on start\activestate. i dont think that dbi comes with activestate but when you install it providing you use ppm the help files will be added.

as far as books go perl in a nutshell provides a chapter on both modules that contain some good examples and complete listings\descriptions on all functions belonging to these modules. perl in a nutshell is only about £14 so its well worth it.

dbi is really easy to use. all you have to do is get the dbi module and then get a dbd module for the database you want to use. dbi provides the interface and framework for vendor specific dbd drivers. the dbd actaully implements the methods which talk to the db.  

dbd modules can be obtained for most dbs from either cpan or activestate\packages\zips. for access use the odbc dbd module, this will work for sql server aswell.

use DBI;
#open the database
$db_handle->connect(dbi:<DBD DRIVER>:<DSN>,'username','password');
#prepare statment
$st_handle = $db_handle->prepare("Some sql ");
#execute it
$st_handle->execute();
#loop through displaying results
while($data = $st_handle->fetchrow_hashref())
{
   print("result : ".$data->{"the_field_name"});
}

see its easy !!. in the connect bit <DSN> is a dsn you have set up for you database, or the address of a db server such as oracle followed by the database name. and <DBD DRIVER> is the name of the dbd driver you want to use. note theres not a use DBD at the top.

some cgi pm

use CGI;
#create a cgi object
$query = new CGI;
#test if there any input parameters
if($query->param())
{
#get on
   $my_value_from_a_form = $query->param('form_value_name');
#print a header out
   print $query->header()
   print loads of html either using lots of print sttments or cgi functions

}                  
                 -
0
 
LVL 1

Expert Comment

by:stephenblade
Comment Utility
Or actually you can read a step by step tutorial on the subject at:

http://perl.about.com/compute/perl/library/weekly/aa120699a.htm

0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

This tutorial will discuss the log-in process using WhizBase. In this article I assume you already know HTML. I will write the code using WhizBase Server Pages, so you need to know some basics in WBSP (you might look at some of my other articles abo…
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 while and for loops in Python.  while loops are used for testing while, or until, a condition is met: The structure of a while loop is as follows:     while <condition>:         do something         repeate: The break statement m…
The viewer will learn how to dynamically set the form action using jQuery.

743 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

17 Experts available now in Live!

Get 1:1 Help Now