Database Reference
In-Depth Information
# Connect to the database and return a database handle
my $dbh = DBI->connect("dbi:Oracle:${net_service_name}", $user, $passwd)
or die "Connect failed: $DBI::errstr";
my $sth = $dbh->prepare("SELECT user FROM dual"); # PARSE
$sth->execute(); # EXECUTE
my @row = $sth->fetchrow_array(); # FETCH
printf ("Connected as user %s\n", $row[0]);
$sth->finish;
$dbh->disconnect; # disconnect from ORACLE instance
Following are example settings for 32-bit Perl in a 64-bit ORACLE_HOME
export PATH=$ORACLE_HOME/perl/bin:$ORACLE_HOME/bin:/usr/bin:/usr/ccs/bin
export PERL5LIB=$ORACLE_HOME/perl/lib:$ORACLE_HOME/perl/lib/site_perl
export LD_LIBRARY_PATH=$ORACLE_HOME/lib32
Let's confirm that these settings are correct.
$ perl perl-dbi-test.pl
Username:
ndebesPassword:
secret
Net Service Name (optional, if ORACLE instance runs locally and ORACLE_SID is set):
ten_tcp.world
Trying to connect to ndebes/ secret@ten_tcp.world
Connected as user NDEBES
The script ran successfully. The connection to the DBMS as well as the execution of SELECT
user FROM dual completed without error.
Windows Environment
On Windows, the Oracle10 g Release 2 Universal Installer (OUI) sets the system environment
variables PATH and PERL5LIB . You may look these up by navigating to Control Panel
System
Advanced
Environment Variables and browsing the list box System Variables . However, it
merely adds %ORACLE_HOME%\bin to PATH and in addition to correct directories in PERL5LIB also
sets some non-existent directories (e.g., %ORACLE_HOME%\perl\5.8.3\lib\MSWin32-x86 ) and
several unnecessary ones.
On Windows, environment variables may be set system-wide, user-specifically, and in an
instance of the command interpreter cmd.exe . 4 User-specific settings override system-wide
settings. If an environment variable is changed in a command interpreter, the modified value
is used instead of the user or system variable set using the Control Panel . On startup, command
interpreters inherit user-specific and system-wide environment variables. If you do not have
permission to change system-wide settings, you can still override them with user-specific settings.
Click Start Run or hold down the Windows key (the one showing a flag) and type R, enter cmd , and
click OK to start a command interpreter.
4.
 
Search WWH ::




Custom Search