jvd has asked for the wisdom of the Perl Monks concerning the following question:

query with perl form commandline runs ok.
same query from browser gives an error.

see details below:

browser error:

Internal Server Error
The server encountered an internal error or misconfiguration and was unable to complete your request.
script:

#!/usr/bin/perl use CGI::Carp('fatalsToBrowser'); use CGI qw(:all); use DBI; print header; $dbh = DBI->connect("DBI:mysql:testjvd:localhost","root","mysqljvd",{ +PrintError => 0}) || die $DBI::errstr; $sth=$dbh->prepare("SELECT * FROM gebr"); $sth->execute(); while ( @ columns = $sth->fetchrow ) { print ( ( map { "$_ " } @columns ) , "\n") ; } $sth->finish(); $dbh->disconnect; exit;
rights:
jvd@jvd_1 cgi-bin$ ll perl_sel* -rwxr-xr-x 1 jvd jvd 474 Sep 11 00:51 perl_select_gebr.pl

apache error_log:

Tue Sep 11 01:45:16 2001 error (2)No such file or directory: exec of /intranet_attema/cgi-bin/perl_select_gebr.pl failed Tue Sep 11 01:45:16 2001 error client 192.168.1.16 Premature end of script headers: /intranet_attema/cgi-bin/perl_select_gebr.pl

test from command-line:

root@jvd_1 cgi-bin# perl perl_sel* test1 Jan (returns correct value) root@jvd_1 cgi-bin# what's (still) wrong here ? (need some wisdom)

Jan van Dijk,The Netherlands
Thanks in advance....

Edited by boo_radley : formatting

Replies are listed 'Best First'.
Re: again mySQL
by wog (Curate) on Sep 11, 2001 at 02:16 UTC
    Your problem appears to be one with the she-bang (#!) line of your script. I can tell this because apache's claiming the exec is failing with "No such file or directory", which is a sign that the kernel is not finding the program specified on the she-bang line of the script. (An error exec'ing means that the perl interperator couldn't be run, so the problem can't be anything in the actual perl code.) I can see two scenerios:

    • /usr/bin/perl is not the perl interperator.
    • You have a stray \x0D (AKA carriage return AKA \r) at the end of each line of the script, so the OS is trying to run the file named /usr/bin/perl\x0D to run your script, which doesn't exsit. This would probably be caused by uploading your file without translating newlines from Windows. It can fixed on the (UNIX) command line with the one-liner perl -pi -e'tr/\r//d' file.

    To test if your problem is one of these see if your script executes on the command line with ./perl_select_gebr.pl. If this returns an error, then you probably have one of those problems. Similarly you can test if you have fixed one of these problems from the command line by seeing if the same works. (update: previous sentence re-worked to actually mention testing fixes, as I meant to say originally.)

    A side note: It's a good idea to use strict and warnings. And -T.

Re: again mySQL
by perrin (Chancellor) on Sep 11, 2001 at 02:14 UTC
    Are you sure your perl is in /usr/bin/perl?
Re: again mySQL
by George_Sherston (Vicar) on Sep 11, 2001 at 02:20 UTC
    I ran your script on my local webserver and MySQL and it worked fine. The only line I had to change to get it to run (without having your db) was
    $dbh = DBI->connect("DBI:mysql:testjvd:localhost","root","mysqljvd",{P +rintError => 0})
    So IMVHO the problem is either that one of those DBI parameters is wrong (which it can't be if it works from the command line) or... well, the apache error_log makes it look like the problem is nothing to do with the script. Are you saving it in the right place? Can you run other scripts that you save in the same place?

    § George Sherston
Re: again mySQL
by higle (Chaplain) on Sep 11, 2001 at 06:34 UTC
    You might also want to make sure that you set your environment variables properly. I've encountered that snafu before...

    higle