Unable to make a MySQL connection through Perl when called in a PHP script -


i'm creating connection mysql database within perl script, called php script. here 2 scripts:

perl:

#!/usr/bin/perl # script name = mycode.pl use dbi; $data_source = q/dbi:mysql:name:localhost/; $user = q/myname/; $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 command line, test.php prints "before..." , "...after" , db connection indeed established within perl code. however, when test.php executed (chrome) browser, prints "before..." , no connection made. , no error message displayed.

why there success on command line not web server?

yes, php shell_exec() function doesn't capture stderr.

to debug code, can add 2>&1 @ end of system command redirect stderr stdout:

$myresult = shell_exec("perl /path/script.pl 2>&1"); 

also, can setup dbi module die if error occurs @ runtime:

$dbh = dbi->connect($data_source,$user, $pwd, { raiseerror => 1, printerror => 0}) or die $dbi::errstr; 

Comments

Popular posts from this blog

css - SVG using textPath a symbol not rendering in Firefox -

Java 8 + Maven Javadoc plugin: Error fetching URL -

order - Notification for user in user account opencart -