calling a perl program from a php script

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • brakesh
    New Member
    • Nov 2006
    • 2

    calling a perl program from a php script

    Hi,
    I am trying to call a perl program (that connects a webserver database) from a php program via a webbrowser. For example : http://development.noa a.gov/test_exec.php?d ataid=8313. The test_exec.php script that calls the perl program is as follows:

    <?php
    error_log("insi de test_exec \n");
    $dataid = $_GET['dataid'];
    $cmd = "/usr/bin/perl /........../db_connect_psql _RS3.pl ". $dataid;
    error_log("data id = $dataid\n");
    exec($cmd);
    ?>

    The code from db_connect_psql _RS3.pl is like so:
    #!/usr/bin/perl

    use DBI;
    use strict;

    # This script connects to the psql database, retrieves the data for a given dataid
    # and creates a xml file with the fgdc specification.

    #open the xml file to prepare the xml document
    open my $FOUT, ">>client.x ml";
    print $FOUT "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n";

    #make connection to the database
    my $database = "db_name";
    my $hostname = "localhost" ;
    my $username = "username";
    my $password = "";

    my $dsn = "DBI:Pg:dbname= $database";

    #my $dbh = DBI->connect($dsn , $username, $password,{ RaiseError => 1, AutoCommit => 0 });

    my $dbh = DBI->connect('DBI:P g:dbname=cwdisc overy','brakesh ','',{ RaiseError => 1, AutoCommit => 0 });
    ...
    bla
    bla
    bla
    ..
    .

    The db_connect_RS3. pl script is getting called. I say this because the client.xml file is getting created and the string "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>" is getting prtinted to it. However the database connection is not being made, and I can't if any errors are being thrown. Can anyone please suggest any error catching mechanism when a perl script is being called by a php program. And does anyone know what is going wrong-- why is the database connectiong is not being made?. The perl script is working fine, because if I run it (stand alone) via the command line, the script produces the desired xml file for a given dataID. But the script doesn't work when called from the php program. Any pointers to solve this will be greatly appreciated.

    -Bhavana.
Working...