我正在通过PHP脚本调用的Perl脚本中创建与MySQL数据库的连接.这是2个脚本:
Perl的:
#!/usr/bin/perl
# script name = MyCode.pl
use DBI;
my $data_source = q/dbi:mysql:name:localhost/;
my $user = q/myname/;
my $pwd = q/pword/;
print "before...\n";
# Connect!
$dbhandle= DBI->connect($data_source,$user,$pwd) or die "can't connect
$data_source: $DBI::errstr \n";
print "...after \n";
Run Code Online (Sandbox Code Playgroud)
PHP:
<?php
// script name = Test.php
$myResult=shell_exec("perl /path/MyCode.pl");
echo $myResult;
?>
Run Code Online (Sandbox Code Playgroud)
在命令行上执行时,Test.php打印"before ..."和"... after",并且在Perl代码中确实建立了DB连接.但是,当从我的(Chrome)浏览器执行Test.php时,所有打印的内容都是"之前......"并且没有建立连接.并且不显示任何错误消息.
为什么在命令行上有成功但在Web服务器上却没有?