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

Hi Monks,

I have a CGI module, which connects to an Oracle Server to retrieve values from it..
Please find the code below..
Now, the issue i am facing is, I am able to see the line 'This is before connecting' in the HTML rendered, but right after this, it stops execution, i cant see any errors, nor can i see any other print statements getting executed after this..
#!/usr/bin/perl use DBI; use CGI; print "Content-Type:text/html\n\n"; print<<__HTML__; <html> <head> </head> <title>Test123</title> <body> __HTML__ print "This is Official\n"; my $DB="MYDB1"; my $HOST="tpvpm12192"; my $PORT="1521"; my $USER="remote_usr"; my $PASS="passItToMe"; $ENV{ORACLE_HOME}="/opt/netcool/oracle"; $ENV{LD_LIBRARY_PATH}="/opt/netcool/oracle"; print "<br>$ENV{LD_LIBRARY_PATH}<br>"; print "This is before connecting\n"; my $MysqlDbh = DBI->connect("DBI:Oracle:host=$HOST;sid=$DB;port=$PORT" +,$USER, $PASS, {RaiseError => 0, AutoCommit => 1,PrintError => 1 }); if (! $MysqlDbh) { print "Error Error Error"; }else{ print "Connect Succeeded!!"; } my $Statement="select * from NodeInformationStore where Node = '123'"; my $Sth = $MysqlDbh->prepare($Statement); if (! $Sth) { print "Unable to prepare query $Statement.\n$DBI::errstr\n"; exit; } if (! $Sth->execute) { print "Unable to execute query $Statement\n$DBI::errstr\n"; exit; }else{ print "This query has been executed"; } print "</html>";


When I run this from commandline, it works fine. However, when invoked from the browser as a cgi, it fails. Could someone please help me out..

Replies are listed 'Best First'.
Re: Connecting to Oracle DB using DBI from CGI script
by Anonymous Monk on May 20, 2010 at 13:52 UTC
    However, when invoked from the browser as a cgi, it fail

    The error message tells you what the problem is (probably permissions or firewall)

    CGI Help Guide

Re: Connecting to Oracle DB using DBI from CGI script
by bart (Canon) on May 20, 2010 at 21:19 UTC
    Problems connecting to Oracle are often caused by required environment variables that aren't set. See what you have in your normal environment where it works, in environment variables that start with the prefix "ORA", for example "ORA_HOME". If you set them the same way for the CGI script, it'll probably work.
      Hey all,
      I was using webtop to launch these CGI scripts, and somehow the Webtop server was blocking the env variables from getting set(probably some security issue)..So i needed to set the env variables system wide using crle.. This solved the issue.. Thanks for all your pointers..
      Good Day..
        Hi Freind, Can you please share the script after setting the env variable as i am also trying to launch it from the webtop, looking forward to your kind reply.
Re: Connecting to Oracle DB using DBI from CGI script
by marto (Cardinal) on May 20, 2010 at 13:58 UTC