I create a connection to a MySQL database in a Perl script, the PHP script is called. Here are two scenarios:
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";
PHP:
<?php // script name = Test.php $myResult=shell_exec("perl /path/MyCode.pl"); echo $myResult; ?>
When executed on the command line, Test.php prints "before ..." and "... after", and the DB connection is indeed established in the Perl code. However, when Test.php is executed from my browser (Chrome), everything that prints is "before ..." and no connection is made. And the error message is not displayed.
Why is there success on the command line, but not from the web server?
Mikep source share