Perl CGI 脚本中的查询结果返回没有数据的空白网页
Query results in Perl CGI script is returning back blank webpage with no data
我是 运行 一个为用户检索密码的脚本,但我得到的是一个空白页面。当我检查 Apache 错误日志时,它说它找不到 Informix Perl 模块。但是我安装了 Informix Perl 模块,并且能够通过命令行脚本连接到我们的 Informix 数据库。
在 Apache 日志中发现错误:
cgi:error] [pid 30132] [client 10.199] AH01215: install_driver(Informix) failed: Can't locate DBD/Informix.pm in @INC (@INC contains: /usr/local/lib64/perl5 /usr/local/share/perl5 /usr/lib64/perl5/vendor_perl /usr/share/perl5/vendor_perl /usr/lib64/perl5 /usr/share/perl5 .) at (eval 7) line 3.,
referer: server.com/cgi-bin/ts_password_retrieval.cgi [Thu Sep 03 17:58:24.8 2015] [cgi:error] [pid 30132] [client 10.199]
AH01215: Perhaps the DBD::Informix perl module hasn't been fully installed,, referer: server.com/cgi-bin/ts_password_retrieval.cgi –
Informix 库的 Perl 版本和位置:
(v5.16.3)
export INFORMIXDIR=/opt/informix
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$INFORMIXDIR/lib:$INFORMIXDIR/lib/cli:$INFORMIXDIR/lib/esql:$INFORMIXDIR/lib/tools
代码生成错误:
#!/usr/bin/perl -w
use CGI::Pretty qw(:standard *table);
use strict;
use warnings;
use DBI;
#use Config::Std;
use vars qw($FICE_CODE $SCHL_NAME $FIRST_NAME $LAST_NAME $TO_ORDER_ID $CH_FLAG $ORDER_STATUS $TO_RECIP_ID $ORDER_STATUS $RECPT_ORDER_STATUS $EMAIL $TO_DELIV_TRANS_ID $PASSWORD $FILE_NAME);
use Data::Dumper;
#&ReadParse(*input);
#Output display
print "Content-type: text/html\n\n";
main();
sub main
{
print "<html><head>\n";
print "<title>Transcript Password Retrieval</title></head>\n";
print "<body>\n";
print "<center>Transcript Password Retrieval</center>\n";
print "</body></html>\n";
if (param('to_id'))
{
my $to_id = param('to_id');#local to_id
my $pwd_select = ("select s.fice_code, s.schl_name, o.first_name, o.last_name, o.to_order_id, o.ch_flag, o.order_status,r.to_recipient_id, r.order_status, r.email, dt.to_deliv_trans_id, dt.password, dt.file_name from to_scprofil s, to_order o, to_recipient r, to_deliv_trans dt where s.to_scprofil_id = o.to_scprofil_id and o.to_order_id = r.to_order_id and r.to_recipient_id = dt.to_recipient_id and o.to_order_id in ($to_id) order by o.to_order_id desc");
my $driver = "Informix";
my $database = "Web1";
my $dsn = "DBI:$driver:dbname=$database";
my $userid = "todd";
my $password = "shumer12";
my $dbh = DBI->connect($dsn, $userid, $password, {RaiseError => 1}) or die $DBI::errstr;
#print "Opened db successfully\n";
my $sth = $dbh->prepare($pwd_select);
$sth ->execute; #make this a global variable might have to revert this back to a locak variable
my $rv = $sth->rows;
while(my $row = $sth->fetchrow_hashref)
{
print hr
print start_table;
foreach my $key (keys %$row)
{
print Tr
(
td(b($key)),
td($row->{$key}),
);
}
print end_table;
#print Dumper $row;
}
exit;
my $output = (our @to_pwd);#send output to the array @to_pwd so it can then be spliced into each row
$to_id = format_to_orderid($to_id);
foreach my $output(@to_pwd)
{
($FICE_CODE, $SCHL_NAME, $FIRST_NAME, $LAST_NAME, $TO_ORDER_ID, $CH_FLAG, $ORDER_STATUS, $TO_RECIP_ID, $ORDER_STATUS, $RECPT_ORDER_STATUS, $EMAIL, $TO_DELIV_TRANS_ID, $PASSWORD, $FILE_NAME)=split(",",$output);#split output with a coma from each row.
if($FICE_CODE eq "fice_code")#header rows
{
print"<tr>/n";
print"<th>$FICE_CODE</th>";
print"<th>$SCHL_NAME</th>";
print"<th>$FIRST_NAME</th>";
print"<th>$LAST_NAME</th>";
print"<th>$TO_ORDER_ID</th>";
print"<th>$CH_FLAG</th>";
print"<th>$ORDER_STATUS</th>";
print"<th>$TO_RECIP_ID</th>";
print"<th>$ORDER_STATUS</th>";
print"<th>$RECPT_ORDER_STATUS</th>";
print"<th>$EMAIL</th>";
print"<th>$TO_DELIV_TRANS_ID</th>";
print"<th>$PASSWORD</th>";
print"<th>$FILE_NAME</th>";
print"<tr/>/n";
print "</table>/n";
next;
}
print"<tr>/n"; #data information from sql
print"<td>$FICE_CODE</td>";
print"<td align 'right'> $SCHL_NAME</td>/n";
print"<td align 'right'> $FIRST_NAME</td>/n";
print"<td align 'right'> $LAST_NAME</td>/n";
print"<td align 'right'> $TO_ORDER_ID</td>/n";
print"<td align 'right'> $CH_FLAG</td>/n";
print"<td align 'right'> $ORDER_STATUS</td>/n";
print"<td align 'right'> $TO_RECIP_ID</td>/n";
print"<td align 'right'> $ORDER_STATUS</td>/n";
print"<td align 'right'> $RECPT_ORDER_STATUS</td>/n";
print"<td align 'right'> $EMAIL</td>/n";
print"<td align 'right'> $TO_DELIV_TRANS_ID</td>/n";
print"<td align 'right'> $PASSWORD</td>/n";
print"<td align 'right'> $FILE_NAME</td>/n";
#finish table data html
print"<tr/>/n";
}
}
else
{
show_form();
}
print"</body></html>\n"
}
sub show_form
{
my $url = url;
print qq{<form name="input" action="ts_password_retrieval.cgi" method="get">\n};
print qq{<table align="center" border="1" bordercolor="black" cellpadding="2" cellspacing="0">\n};
print qq{<tr>};
print qq{<td align="right">Please enter the Transcript Order ID #</td};
print qq{</tr>\n};
print qq{<td align="left"><input type"text" width="7" name="to_id" value="">};
print qq{<BR>Place each Transcript Order ID separated by a space</td>};
print qq{</table><center><input type="submit" value="Submitted"></center></form>\n};
}
sub format_to_orderid
{
my $in= shift;
my $out = join ',', split /\s/, $in;
return $out;
}
试图通过 dump_results() 来解决问题,但我仍然得到一个空白页面
#!/usr/bin/perl -w
use CGI::Pretty qw(:standard *table);
use strict;
use warnings;
use DBI;
#use Config::Std;
use vars qw($FICE_CODE $SCHL_NAME $FIRST_NAME $LAST_NAME $TO_ORDER_ID $CH_FLAG $ORDER_STATUS $TO_RECIP_ID $ORDER_STATUS $RECPT_ORDER_STATUS $EMAIL $TO_DELIV_TRANS_ID $PASSWORD $FILE_NAME);
use Data::Dumper;
#&ReadParse(*input);
#Output display
print "Content-type: text/html\n\n";
main();
sub main
{
print "<html><head>\n";
print "<title>Transcript Password Retrieval</title></head>\n";
print "<body>\n";
print "<center>Transcript Password Retrieval</center>\n";
print "</body></html>\n";
if (param('to_id'))
{
my $to_id = param('to_id');#local to_id
$to_id = format_spn_string($to_id);
my $pwd_select = ("select s.fice_code, s.schl_name, o.first_name, o.last_name, o.to_order_id, o.ch_flag, o.order_status, r.to_recipient_id, r.order_status,r.email, dt.to_deliv_trans_id, dt.password, dt.file_name from to_scprofil s, to_order o, to_recipient r, to_deliv_trans dt where s.to_scprofil_id = o.to_scprofil_id and o.to_order_id = r.to_order_id and r.to_recipient_id = dt.to_recipient_id and o.to_order_id in ($to_id) order by o.to_order_id desc");
my $driver = "Informix";
my $database = "Web1";
my $dsn = "DBI:$driver:dbname=$database";
my $userid = "user";
my $password = "password";
my $dbh = DBI->connect($dsn, $userid, $password, {RaiseError => 1}) or die $DBI::errstr;
#print "Opened db successfully\n";
my $sth = $dbh->prepare($pwd_select);
$sth ->execute; #make this a global variable might have to revert this back to a local variable
$sth -> dump_results();
$sth->finish();
$dbh->disconnect();
}
else
{
show_form();
}
print"</body></html>\n"
}
sub show_form
{
my $url = url;
print qq{<form name="input" action="ts_password_retrieval.cgi" method="get">\n};
print qq{<table align="center" border="1" bordercolor="black" cellpadding="2" cellspacing="0">\n};
print qq{<tr>};
print qq{<td align="right">Please enter the ID #</td};
print qq{</tr>\n};
print qq{<td align="left"><input type"text" width="7" name="to_id" value="">};
print qq{<BR>Place each ID # separated by a space</td>};
print qq{</table><center><input type="submit" value="Submit"></center></form>\n};
}
sub format_to_orderid
{
my $in= shift;
my $out = join ',', split /\s/, $in;
return $out;
}
我是 DBD::Informix 的守护者 — 也就是开发者和维护者。
除非您以我不知道的方式修改了 DBD::Informix 中的代码,否则表示法:
my $dsn = "DBI:$driver:dbname=$database";
将不起作用。 Informix 不接受连接字符串中的 dbname=
(或者更准确地说,不解释它,因此它尝试连接到名为 dbname=whatever@wherever
的数据库并失败,因为 =
无效在数据库名称中)。
因此,从 DSN 中删除 dbname=
部分。
来自 perldoc DBI
:
"connect"
$dbh = DBI->connect($data_source, $username, $password)
or die $DBI::errstr;
$dbh = DBI->connect($data_source, $username, $password, \%attr)
or die $DBI::errstr;
Establishes a database connection, or session, to the requested
$data_source. Returns a database handle object if the connection succeeds.
Use "$dbh->disconnect" to terminate the connection.
If the connect fails (see below), it returns "undef" and sets both
$DBI::err and $DBI::errstr. (It does not explicitly set $!.) You should
generally test the return status of "connect" and "print $DBI::errstr" if
it has failed.
…
The $data_source value must begin with ""dbi:"driver_name":"". The
driver_name specifies the driver that will be used to make the connection.
(Letter case is significant.)
…
Examples of $data_source values are:
dbi:DriverName:database_name
dbi:DriverName:database_name@hostname:port
dbi:DriverName:database=database_name;host=hostname;port=port
There is no standard for the text following the driver name. Each driver
is free to use whatever syntax it wants. The only requirement the DBI
makes is that all the information is supplied in a single string. You must
consult the documentation for the drivers you are using for a description
of the syntax they require.
(已强调。)
来自perldoc DBD::Informix
CONNECTING TO A DATABASE
To connect to a database, you use the connect function, which yields a
valid database handle if it is successful. …
…
$dbh = DBI->connect("dbi:Informix:$database");
$dbh = DBI->connect("dbi:Informix:$database", $user, $pass);
$dbh = DBI->connect("dbi:Informix:$database", $user, $pass, %attr);
The DBI connect method strips the 'dbi:' prefix from the first argument
and loads the DBD module identified by the next string (Informix in this
case). The string following the second colon is all that is passed to the
DBD::Informix code. With this format, you do not have to specify the
username or password. Note that if you specify the username but not the
password, DBD::Informix will silently ignore the username. …
我是 运行 一个为用户检索密码的脚本,但我得到的是一个空白页面。当我检查 Apache 错误日志时,它说它找不到 Informix Perl 模块。但是我安装了 Informix Perl 模块,并且能够通过命令行脚本连接到我们的 Informix 数据库。
在 Apache 日志中发现错误:
cgi:error] [pid 30132] [client 10.199] AH01215: install_driver(Informix) failed: Can't locate DBD/Informix.pm in @INC (@INC contains: /usr/local/lib64/perl5 /usr/local/share/perl5 /usr/lib64/perl5/vendor_perl /usr/share/perl5/vendor_perl /usr/lib64/perl5 /usr/share/perl5 .) at (eval 7) line 3.,
referer: server.com/cgi-bin/ts_password_retrieval.cgi [Thu Sep 03 17:58:24.8 2015] [cgi:error] [pid 30132] [client 10.199]
AH01215: Perhaps the DBD::Informix perl module hasn't been fully installed,, referer: server.com/cgi-bin/ts_password_retrieval.cgi –
Informix 库的 Perl 版本和位置:
(v5.16.3)
export INFORMIXDIR=/opt/informix
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$INFORMIXDIR/lib:$INFORMIXDIR/lib/cli:$INFORMIXDIR/lib/esql:$INFORMIXDIR/lib/tools
代码生成错误:
#!/usr/bin/perl -w
use CGI::Pretty qw(:standard *table);
use strict;
use warnings;
use DBI;
#use Config::Std;
use vars qw($FICE_CODE $SCHL_NAME $FIRST_NAME $LAST_NAME $TO_ORDER_ID $CH_FLAG $ORDER_STATUS $TO_RECIP_ID $ORDER_STATUS $RECPT_ORDER_STATUS $EMAIL $TO_DELIV_TRANS_ID $PASSWORD $FILE_NAME);
use Data::Dumper;
#&ReadParse(*input);
#Output display
print "Content-type: text/html\n\n";
main();
sub main
{
print "<html><head>\n";
print "<title>Transcript Password Retrieval</title></head>\n";
print "<body>\n";
print "<center>Transcript Password Retrieval</center>\n";
print "</body></html>\n";
if (param('to_id'))
{
my $to_id = param('to_id');#local to_id
my $pwd_select = ("select s.fice_code, s.schl_name, o.first_name, o.last_name, o.to_order_id, o.ch_flag, o.order_status,r.to_recipient_id, r.order_status, r.email, dt.to_deliv_trans_id, dt.password, dt.file_name from to_scprofil s, to_order o, to_recipient r, to_deliv_trans dt where s.to_scprofil_id = o.to_scprofil_id and o.to_order_id = r.to_order_id and r.to_recipient_id = dt.to_recipient_id and o.to_order_id in ($to_id) order by o.to_order_id desc");
my $driver = "Informix";
my $database = "Web1";
my $dsn = "DBI:$driver:dbname=$database";
my $userid = "todd";
my $password = "shumer12";
my $dbh = DBI->connect($dsn, $userid, $password, {RaiseError => 1}) or die $DBI::errstr;
#print "Opened db successfully\n";
my $sth = $dbh->prepare($pwd_select);
$sth ->execute; #make this a global variable might have to revert this back to a locak variable
my $rv = $sth->rows;
while(my $row = $sth->fetchrow_hashref)
{
print hr
print start_table;
foreach my $key (keys %$row)
{
print Tr
(
td(b($key)),
td($row->{$key}),
);
}
print end_table;
#print Dumper $row;
}
exit;
my $output = (our @to_pwd);#send output to the array @to_pwd so it can then be spliced into each row
$to_id = format_to_orderid($to_id);
foreach my $output(@to_pwd)
{
($FICE_CODE, $SCHL_NAME, $FIRST_NAME, $LAST_NAME, $TO_ORDER_ID, $CH_FLAG, $ORDER_STATUS, $TO_RECIP_ID, $ORDER_STATUS, $RECPT_ORDER_STATUS, $EMAIL, $TO_DELIV_TRANS_ID, $PASSWORD, $FILE_NAME)=split(",",$output);#split output with a coma from each row.
if($FICE_CODE eq "fice_code")#header rows
{
print"<tr>/n";
print"<th>$FICE_CODE</th>";
print"<th>$SCHL_NAME</th>";
print"<th>$FIRST_NAME</th>";
print"<th>$LAST_NAME</th>";
print"<th>$TO_ORDER_ID</th>";
print"<th>$CH_FLAG</th>";
print"<th>$ORDER_STATUS</th>";
print"<th>$TO_RECIP_ID</th>";
print"<th>$ORDER_STATUS</th>";
print"<th>$RECPT_ORDER_STATUS</th>";
print"<th>$EMAIL</th>";
print"<th>$TO_DELIV_TRANS_ID</th>";
print"<th>$PASSWORD</th>";
print"<th>$FILE_NAME</th>";
print"<tr/>/n";
print "</table>/n";
next;
}
print"<tr>/n"; #data information from sql
print"<td>$FICE_CODE</td>";
print"<td align 'right'> $SCHL_NAME</td>/n";
print"<td align 'right'> $FIRST_NAME</td>/n";
print"<td align 'right'> $LAST_NAME</td>/n";
print"<td align 'right'> $TO_ORDER_ID</td>/n";
print"<td align 'right'> $CH_FLAG</td>/n";
print"<td align 'right'> $ORDER_STATUS</td>/n";
print"<td align 'right'> $TO_RECIP_ID</td>/n";
print"<td align 'right'> $ORDER_STATUS</td>/n";
print"<td align 'right'> $RECPT_ORDER_STATUS</td>/n";
print"<td align 'right'> $EMAIL</td>/n";
print"<td align 'right'> $TO_DELIV_TRANS_ID</td>/n";
print"<td align 'right'> $PASSWORD</td>/n";
print"<td align 'right'> $FILE_NAME</td>/n";
#finish table data html
print"<tr/>/n";
}
}
else
{
show_form();
}
print"</body></html>\n"
}
sub show_form
{
my $url = url;
print qq{<form name="input" action="ts_password_retrieval.cgi" method="get">\n};
print qq{<table align="center" border="1" bordercolor="black" cellpadding="2" cellspacing="0">\n};
print qq{<tr>};
print qq{<td align="right">Please enter the Transcript Order ID #</td};
print qq{</tr>\n};
print qq{<td align="left"><input type"text" width="7" name="to_id" value="">};
print qq{<BR>Place each Transcript Order ID separated by a space</td>};
print qq{</table><center><input type="submit" value="Submitted"></center></form>\n};
}
sub format_to_orderid
{
my $in= shift;
my $out = join ',', split /\s/, $in;
return $out;
}
试图通过 dump_results() 来解决问题,但我仍然得到一个空白页面
#!/usr/bin/perl -w
use CGI::Pretty qw(:standard *table);
use strict;
use warnings;
use DBI;
#use Config::Std;
use vars qw($FICE_CODE $SCHL_NAME $FIRST_NAME $LAST_NAME $TO_ORDER_ID $CH_FLAG $ORDER_STATUS $TO_RECIP_ID $ORDER_STATUS $RECPT_ORDER_STATUS $EMAIL $TO_DELIV_TRANS_ID $PASSWORD $FILE_NAME);
use Data::Dumper;
#&ReadParse(*input);
#Output display
print "Content-type: text/html\n\n";
main();
sub main
{
print "<html><head>\n";
print "<title>Transcript Password Retrieval</title></head>\n";
print "<body>\n";
print "<center>Transcript Password Retrieval</center>\n";
print "</body></html>\n";
if (param('to_id'))
{
my $to_id = param('to_id');#local to_id
$to_id = format_spn_string($to_id);
my $pwd_select = ("select s.fice_code, s.schl_name, o.first_name, o.last_name, o.to_order_id, o.ch_flag, o.order_status, r.to_recipient_id, r.order_status,r.email, dt.to_deliv_trans_id, dt.password, dt.file_name from to_scprofil s, to_order o, to_recipient r, to_deliv_trans dt where s.to_scprofil_id = o.to_scprofil_id and o.to_order_id = r.to_order_id and r.to_recipient_id = dt.to_recipient_id and o.to_order_id in ($to_id) order by o.to_order_id desc");
my $driver = "Informix";
my $database = "Web1";
my $dsn = "DBI:$driver:dbname=$database";
my $userid = "user";
my $password = "password";
my $dbh = DBI->connect($dsn, $userid, $password, {RaiseError => 1}) or die $DBI::errstr;
#print "Opened db successfully\n";
my $sth = $dbh->prepare($pwd_select);
$sth ->execute; #make this a global variable might have to revert this back to a local variable
$sth -> dump_results();
$sth->finish();
$dbh->disconnect();
}
else
{
show_form();
}
print"</body></html>\n"
}
sub show_form
{
my $url = url;
print qq{<form name="input" action="ts_password_retrieval.cgi" method="get">\n};
print qq{<table align="center" border="1" bordercolor="black" cellpadding="2" cellspacing="0">\n};
print qq{<tr>};
print qq{<td align="right">Please enter the ID #</td};
print qq{</tr>\n};
print qq{<td align="left"><input type"text" width="7" name="to_id" value="">};
print qq{<BR>Place each ID # separated by a space</td>};
print qq{</table><center><input type="submit" value="Submit"></center></form>\n};
}
sub format_to_orderid
{
my $in= shift;
my $out = join ',', split /\s/, $in;
return $out;
}
我是 DBD::Informix 的守护者 — 也就是开发者和维护者。
除非您以我不知道的方式修改了 DBD::Informix 中的代码,否则表示法:
my $dsn = "DBI:$driver:dbname=$database";
将不起作用。 Informix 不接受连接字符串中的 dbname=
(或者更准确地说,不解释它,因此它尝试连接到名为 dbname=whatever@wherever
的数据库并失败,因为 =
无效在数据库名称中)。
因此,从 DSN 中删除 dbname=
部分。
来自 perldoc DBI
:
"connect"
$dbh = DBI->connect($data_source, $username, $password) or die $DBI::errstr; $dbh = DBI->connect($data_source, $username, $password, \%attr) or die $DBI::errstr;
Establishes a database connection, or session, to the requested $data_source. Returns a database handle object if the connection succeeds. Use "$dbh->disconnect" to terminate the connection.
If the connect fails (see below), it returns "undef" and sets both $DBI::err and $DBI::errstr. (It does not explicitly set $!.) You should generally test the return status of "connect" and "print $DBI::errstr" if it has failed.
…
The $data_source value must begin with ""dbi:"driver_name":"". The driver_name specifies the driver that will be used to make the connection. (Letter case is significant.)
…
Examples of $data_source values are:
dbi:DriverName:database_name dbi:DriverName:database_name@hostname:port dbi:DriverName:database=database_name;host=hostname;port=port
There is no standard for the text following the driver name. Each driver is free to use whatever syntax it wants. The only requirement the DBI makes is that all the information is supplied in a single string. You must consult the documentation for the drivers you are using for a description of the syntax they require.
(已强调。)
来自perldoc DBD::Informix
CONNECTING TO A DATABASE
To connect to a database, you use the connect function, which yields a valid database handle if it is successful. …
…
$dbh = DBI->connect("dbi:Informix:$database"); $dbh = DBI->connect("dbi:Informix:$database", $user, $pass); $dbh = DBI->connect("dbi:Informix:$database", $user, $pass, %attr);
The DBI connect method strips the 'dbi:' prefix from the first argument and loads the DBD module identified by the next string (Informix in this case). The string following the second colon is all that is passed to the DBD::Informix code. With this format, you do not have to specify the username or password. Note that if you specify the username but not the password, DBD::Informix will silently ignore the username. …