Solved

DBI & CGI

Posted on 2000-02-26
3
186 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
ID: 2561524
perldoc CGI

and

perldoc DBI

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

Accepted Solution

by:
makerp earned 50 total points
ID: 2562376
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
ID: 2594585
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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Suggested Solutions

It is becoming increasingly popular to have a front-page slider on a web site. Nearly every TV website,  magazine or online news has one on their site, and even some e-commerce sites have one. Today you can use sliders with Joomla, WordPress or …
This article is meant to give a basic understanding of how to use R Sweave as a way to merge LaTeX and R code seamlessly into one presentable document.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

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

24 Experts available now in Live!

Get 1:1 Help Now