Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW

Oracle DBI

by aging acolyte (Pilgrim)
on Jan 21, 2003 at 15:51 UTC ( [id://228715] : perlquestion . print w/replies, xml ) Need Help??

aging acolyte has asked for the wisdom of the Perl Monks concerning the following question:


I am confused (my usual state) but right now I have reason!

I am trying to get a perl script to talk to an Oracle database. Oracle DBD seems to be installed correctly.But I get this strange error (see below).

My perl script sits on a linux box and my Oracle dB on a sun server. However, I am confident that Oracle is set up correctly as I can access it via sqlplus from my linux box.

A search of the site revealed a few related links 28533 but all seem to indicate that the Oracle library(LD_LIBRARY_PATH) isn't installed correctly. But I think it is.

Any ideas?



#!/usr/bin/perl -w BEGIN { $ENV{ORACLE_BASE} = '/usr/local/share/oracle'; $ENV{ORACLE_HOME} = "$ENV{ORACLE_BASE}/815client"; $ENV{LD_LIBRARY_PATH} = "$ENV{ORACLE_HOME}/lib"; $ENV{TNS_ADMIN} = "$ENV{ORACLE_HOME}/network/admin"; } use strict; use CGI; use CGI::Carp 'fatalsToBrowser'; use DBI; use DBD::Oracle; use Data::Dumper; . . . print "path = $ENV{LD_LIBRARY_PATH} \n"; my $dbh = DBI->connect("dbi:Oracle:database=XYZDEV01", 'user', 'pass') + || die $DBI::errstr; . . .
generates the error message:
perl: relocation error: /usr/lib/perl/5.6.1/auto/DBD/Oracle/ + undefined symbol: OCIInitialize
Commenting out the my $dbh line.. reveals that
path = /usr/local/share/oracle/815client/lib
as it should be!

Replies are listed 'Best First'.
Re: Oracle DBI
by mpeppler (Vicar) on Jan 21, 2003 at 18:53 UTC
    You can't set or modify LD_LIBRARY_PATH in the script itself (or in any program) and have it affect the loading of shared libraries for that program. Setting LD_LIBRARY_PATH will only affect child processes of the process where it is set.

    If you are running the Apache web server add an entry in httpd.conf that sets LD_LIBRARY_PATH correctly (something like SetEnv LD_LIBRARY_PATH /usr/local/(...)/lib should work). The alternative is to set the LD_LIBRARY_PATH in a shell script wrapper (ugh!).

    Or, if you are running linux, add the Oracle library path to /etc/ and avoid the whole LD_LIBRARY_PATH issue altogether.


Re: Oracle DBI
by OM_Zen (Scribe) on Jan 21, 2003 at 16:12 UTC
    Hi ,

    The BEGIN block is not necessary and also chech the ORACLE_ENV path in the file system .

    use DBI;

    alone and the use DBD::Oracle is not needed as it is instantiated in DBI.Please check all the oracle environment variables in the file system


      I added the begin block as one of the links suggested that oracle envirnoment variables may not be being propagated properly and so I was trying to force them to behave.

      The use DBD::Oracle is there for the same reason.

      As far as I can tell, all my oracle environment variables are correct.

      But thanks for your thoughts anyway.


Re: Oracle DBI
by OM_Zen (Scribe) on Jan 21, 2003 at 18:12 UTC
    Hi ,

    The oracle environment variables ,open and write in a separate file and do this

    require "./";

    in your present pl ,the be the file where you set the environment variables instead of in BEGIN and then compile the code and you should get the environment variables recognized correctly
Re: Oracle DBI
by perrin (Chancellor) on Jan 21, 2003 at 16:58 UTC
    Troubleshoot it with a command-line script first, before you try it in a CGI. Oracle problems are often due to file permissions or environment settings.