如何通过 Perl CGI 脚本使用数据库服务器?

发布于 2024-07-08 10:39:28 字数 209 浏览 7 评论 0原文

我的程序已经可以运行了,我有 Perl(GUI 窗口),我可以在其中输入数据,将数据传递到网页(使用 Tomcat 服务器,JSP),然后保存到 oracle 数据库。 我想要的是使用 Perl CGI 从 Oracle 数据库检索/提取数据的搜索参数(webapp)。 是否可以? 或者有什么建议来解决我的程序? 谢谢!:-)

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 database. What I want is to make search parameter (webapp) that retrieve/extract data from the Oracle database using Perl CGI. Is it possible? Or any suggestions to solve my program? Thanks!:-)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

梅倚清风 2024-07-15 10:39:28

是的,您可以使用 DBIDBD::Oracle 模块。

然而,Oracle 也存在一些问题。 我记得 Oracle 8 的一些乐趣和游戏,所以这些可能不再适用,但它确实需要设置 ENV 变量,如 ORACLE_HOME、ORACLE_BASE 和 Oracle 8。 在某些情况下,ORACLE_SID。

DBD::Oracle 文档确实对此进行了讨论,并且还提到了另一个 ENV 变量 TWO_TASK。 因此,使其正常工作可能取决于...

  • 您运行的 Oracle 版本是什么,
  • 是否有侦听器(我认为您确实需要像 CGI 这样的网络访问?)
  • 您使用的 SQL*Net 版本是什么。

看起来令人畏惧,但您可能需要的只是在网络服务器中添加这些 ENV 变量(iPlanet 是我当时使用的)。 或者从 DBD::Oracle 文档中它给出...

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。 上面假设您在与 Oracle 相同的服务器上运行 CGI 脚本! 如果没有,那么这些 ENV 变量是多余的,您可以这样做(从我的旧脚本中提取!)...

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" );

但是我确实记得必须在 Oracle 服务器上调整类似 TNLISTENER.CONF 的内容(这是几年前的事)所以我有点记不住了!)并且我很确定您需要下载一些客户端 Oracle 库(您可以从他们的网站获得)。

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).

暖阳 2024-07-15 10:39:28

技术混合有什么具体原因吗? 为什么不使用 servlet/JSP?

如果您必须使用 Perl,那么您需要选择运行 Perl 脚本的 Web 服务器。

通常,这将是使用 mod_perl 的 Apache。

但是,如果您只想将其用于一些管理脚本,那么您可以按照概述从 tomcat 运行 Perl 此处

一旦您成功运行了一个简单的 perl 脚本,那么我将考虑使用 DBI/DBD::Oracle 访问您的数据库?

希望这可以帮助...

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...

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文