How can I use a database server from a Perl CGI script?

后端 未结 2 1045
情话喂你
情话喂你 2021-01-28 06:12

My program works already, I have Perl (GUI Window) where I can input data, data passed to the webpage (using to Tomcat server, JSP) and then saved it to oracle

相关标签:
2条回答
  • 2021-01-28 06:36

    Yes you can by using DBI and DBD::Oracle modules.

    However there are some gotchas with Oracle. I remember a few fun and games with Oracle 8 so these may no longer be applicable but it did require setting ENV variables like ORACLE_HOME, ORACLE_BASE & ORACLE_SID in some cases.

    The DBD::Oracle doc does go into this and also mentions another ENV variable TWO_TASK. So getting it to work may depend on....

    • what version of Oracle you have running
    • whether you have listener up (which I think u do need for network access like CGI?)
    • what version SQL*Net your using.

    Seems daunting but all you will probably need is to add these ENV variables in the webserver (iPlanet was what I was using at that time). Alternatively from the DBD::Oracle doc it gives...

    BEGIN {
      $ENV{ORACLE_HOME} = '/home/oracle/product/10.x.x';
      $ENV{TWO_TASK}    = 'DB';
    }
    $dbh = DBI->connect('dbi:Oracle:','scott', 'tiger');
    #  - or -
    $dbh = DBI->connect('dbi:Oracle:','scott/tiger');
    

    PS. The above assumes you are running CGI script on same server as Oracle! If not, then those ENV variables are superfluous and you can just do this (pulled from an old script of mine!)...

    my $db = DBI->connect("dbi:Oracle:host=$host;sid=$database", $user, $pass, 
      { RaiseError => 0, PrintError => 0 } )
      or croak( "Unable to connect to DB - $DBI::errstr" );
    

    However I do recall having to tweak something like TNLISTENER.CONF on the Oracle server (this was some years ago so memory fails me a bit!) and I'm pretty sure you need to download some client Oracle library (which you can get from their site).

    0 讨论(0)
  • 2021-01-28 06:39

    Any specific reason for the mix in technologies? Why not use a servlet/JSP?

    If you must use Perl, then you need to choose what web-server will run your Perl script.

    Normally, this would be Apache using mod_perl.

    But if you only intend to use this for a few admin scripts, then you can run Perl from tomcat as outlined here.

    Once you have managed to get a simple perl script running, then I would look into using DBI/DBD::Oracle to access your database?

    Hope this helps...

    0 讨论(0)
提交回复
热议问题