Oracle B12255-01 Manuale Utente

Pagina di 224
mod_perl
7-16
Oracle HTTP Server Administrator’s Guide
Database Usage Notes
This section provides information for mod_perl users working with databases. It
explains how to test a local database connection and set character forms.
Using Perl to Access the Database
The following section contains information about using Perl to access the database.
Perl scripts access databases using the DBI/DBD driver for Oracle. The DBI/DBD
driver is part of Oracle Database. It calls Oracle Callable Interface (OCI) to access
the databases.
DBI must be enabled in
 for DBI to function. To do this, perform the
following steps:
1.
Edit httpd.conf using a text editor.
2.
Search for “PerlModule Apache: :DBI”.
3.
Uncomment the line “PerlModule Apache: :DBI”.
4.
Restart Oracle HTTP Server using the following commands:
UNIX: ORACLE_HOME/opmn/bin> opmnctl [verbose] restartproc
ias-component=HTTP_Server
Windows: ORACLE_HOME\opmn\bin> opmnctl [verbose] restartproc
ias-component=HTTP_Server
Files must be copied to ORACLE_HOME/Apache/Apache/cgi-bin
Example 7–1
Using Perl to Access the Database
#!<ORACLE_HOME>perl/bin/perl -w
  use DBI;
  my $dataSource = "host=<hostname.domain>;sid=<orclsid>;port=1521";
  my $userName = "scott";
  my $password = "tiger";
  my $dbhandle = DBI->connect("dbi:Oracle:$dataSource", $userName, $password)
    or die "Can’t connect to the Oracle Database: $DBI::errstr\n";
  print "Content-type: text/plain\n\n";
  print "Database connection successful.\n";
  ### Now disconnect from the database
  $dbhandle->disconnect
    or warn "Database disconnect failed; $DBI::errstr\n";
  exit;