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.noaa.gov/test_exec.php?dataid=8313. The test_exec.php script that calls the perl program is as follows:
<?php
error_log("inside test_exec \n");
$dataid = $_GET['dataid'];
$cmd = "/usr/bin/perl /........../db_connect_psql_RS3.pl ". $dataid;
error_log("dataid = $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.xml";
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:Pg:dbname=cwdiscovery','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.
2 1919
I would suggest that you add an "or die" to the creation of the database handle. -
my $dbh = DBI->connect('DBI:Pg:dbname=cwdiscovery', 'brakesh', '', {RaiseError => 1, AutoCommit => 0})
-
or die "database connect failed";
-
I have no experience with calling perl from a php script. So I do not know how the php script will react to a die, but it's all I can think to suggest.
#!/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.xml";
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:Pg:dbname=cwdiscovery','brakesh','', { RaiseError => 1, AutoCommit => 0 });
...
for a start you should use warnings and strict ie lines 2
use warnings;
Is there no password on the database?
have you checked /var/log/httd/error_log (assuming linux/unix here)
you can follow it by typing in a terminal tail -f /var/log/httd/error_log
If nothing is appearing in error log it may be worth converting to CGI script and checking ie:
add
use CGI
print header()
print start_html
after use strict
then print end_html at end of file
make executable and copy to cgi-bin directory
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Shailan |
last post by:
Hi
Im having trouble with the following code that seems to be behave
differently when called from the browser as opposed to the command
line. The calling script is a cgi that forks, with the...
|
by: David Meier |
last post by:
Hi all,
I am not a very skilled C programmer yet and I need the help of the
list bad. OK, here is the problem:
I have written a SIEVE module coded in C for the cyrus imapd mail
server. This...
|
by: sir.linying |
last post by:
My php script is to call perl scipt which makes use of
Spreadsheet::ParseExcel module to parse Excel file. I am able to launch
php script from command line so that perl script can run and properly...
|
by: David Bear |
last post by:
I have a hash function written by another organization that I need to use.
It is implemented in perl. I've been attempting to decode what they are
doing in their hash function and it is taking way...
|
by: brakesh |
last post by:
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.noaa.gov/test_exec.php?dataid=8313. The...
|
by: rahulthathoo |
last post by:
Hi,
After i finish some amount of computation using a perl script, i need
to send out an email to a receipient which can change and is known to
the Perl script. Is there a way to call the...
|
by: KevinADC |
last post by:
Note: You may skip to the end of the article if all you want is the perl code.
Introduction
Uploading files from a local computer to a remote web server has many useful purposes, the most...
|
by: Archanak |
last post by:
Hi,
I am using 2-level CSS Drop Down Menu in my perl/CGI program.
here is the code.
#!c:/perl/bin/perl.exe
use CGI qw(:standard);
|
by: happyse27 |
last post by:
Hi All,
I got this apache errors(see section A1 and A2 below) when I used a html(see section b below) to activate acctman.pl(see section c below). Section D below is part of the configuration...
|
by: KevinADC |
last post by:
Note: You may skip to the end of the article if all you want is the perl code.
Introduction
Many websites have a form or a link you can use to download a file. You click a form button or click...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
| |