Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Usenet -> c.d.o.server -> Re: CGI call to an Oracle Server

Re: CGI call to an Oracle Server

From: <kirk_at_kaybee.org>
Date: 18 Feb 2000 22:24:48 GMT
Message-ID: <88kgrg$sfu$2@news-int.gatech.edu>


Stephen Wang <wangste_at_flux.cpmc.columbia.edu> wrote:
: Thanks for the information. I guess that I did not ask my question in a
: correct way. I basically need to some scripts in C or perl that does the
: database connection and getting results. I know if I search I can find plenty of
: examples but I thought asking the question at this newsgroup might give me a
: quick answer.

I can help with some PERL examples. I am still trying to get the C precompiler to work... The script below is written to be run from Apache's mod_perl interface. What mod_perl does is allow the script's variables to persist across CGI requests. It also keeps the modules in memory. When doing Oracle stuff from these CGI scripts, I consider the use of mod_perl mandatory.

#!/usr/bin/perl -w

use CGI;
use DBI;

################ Initialization Stuff ###############

unless ($init_done) {

   # Create CGI object
   $cgi = new CGI;
}

# Print standard header
print $cgi->header;

unless ($init_done) {

   $ENV{ORACLE_HOME} = "/mnt/oracle/OraHome";    # Create database connection...
   unless ( $dbh = DBI->connect('DBI:Oracle:host=blah.com;sid=test', 'test', 'test', { RaiseError => 1, AutoCommit => 1 }) ) {

      print "Could not connect to database.\n";
      exit;

   }
   $init_done = 1;
}

############## End Initialization Stuff #############

print "Database results:<P>\n";

$statement = "select * from users where u_name = 'Kirk'";
$sth = $dbh->prepare($statement);
$sth->execute();

while (@row = $sth->fetchrow_array) {

   print "@row<P>\n";
}

exit;

--
 Kirk Bauer -- CmpE, Georgia Tech -- kirk_at_kaybee.org -- Avid Linux User

    GT Sport Parachuting Club! http://cyberbuzz.gatech.edu/skydive      Opinions expressed are my own, but they should be everybody's. Received on Fri Feb 18 2000 - 16:24:48 CST

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US