当我从命令行运行perl脚本时,它可以工作,但不能在浏览器上工作。有人可以建议吗?
OS => Red Hat Enterprise Linux version 7.6
Perl => v5.28.0 built for x86_64-linux
Oracle => 12.2.0
DBI => 1.642
DBD::Oracle => 1.76
Apache => Server Version : Apache/2.4.6 (Red Hat Enterprise Linux)
当我在命令行上执行一个简单的Perl / CGI脚本以连接到ORACLE数据库时,它将起作用并带回数据。当我通过浏览器运行以下脚本时,该脚本不起作用并产生错误消息
#!/usr/bin/perl –w
Use CGI qw(:standard);
use CGI::Carp qw(fatalsToBrowser);
use DBI;
sub oracle_connect
{
$sid = "OASISL";
$ENV{'ORACLE_HOME'} = '/app/oracle/product/12.2.0/dbhome_1/bin';
$ENV{'TNS_ADMIN'}
='/app/oracle/product/12.2.0/dbhome_1/network/admin';
$ENV{'LD_LIBRARY_PATH'} = '/app/oracle/product/12.2.0/dbhome_1/lib';
$ENV{'NLS_LANG'} = 'American_America.AL32UTF8';
$dbuser = "*********";
$password = "********";
return DBI->connect("dbi:Oracle:$sid", $dbuser, $password,
{PrintError => 1, RaiseError => 0, AutoCommit => 0});
}
sub oracle_connection_failure
{
print header(), "<br>
<br><center>ORACLE Connection failure.</centre></font>", end_html;
}
sub perform_test
{
$sql_cursor = "
SELECT * FROM $dbuser.table_name
WHERE USER_NAME = 'test'";
print header(), "
<html>
<head>
<title>Oracle Test</title>
</head>";
$sth = $dbh->prepare($sql_cursor);
$sth->execute();
while (@data_returned = $sth->fetchrow_array())
{
print $data_returned[0] . " " . $data_returned[1] . ", " .
$data_returned[2] . "<br>";
}
$sth->finish();
print end_html;
}
($dbh = oracle_connect()) || die oracle_connection_failure();
perform_test;
$dbh->disconnect();
我原本希望看到一条记录,但出现以下错误
[Thu Feb 14 16:09:58.752971 2019] [cgi:error] [pid 9814] [client 000.000.00.000:25047] AH01215:[Thu Feb 14 16:09:58 2019] oracle_test_srv_oasis_01.pl: DBI connect('','$ dbuse',...)失败:错误OCIEnvNlsCreate。在/var/www/cgi-bin/oasis/oracle_test_srv_oasis_01.pl第58行中,检查ORACLE_HOME(Linux)env var或PATH(Windows)和/或NLS设置,权限等。