CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
Search Posts SEARCH
Who's Online WHO'S
Log in LOG

Home: Perl Programming Help: DBI:
DBI program works in IDE but not in a Web Page


New User

Apr 30, 2008, 11:06 AM

Post #1 of 2 (5009 views)
DBI program works in IDE but not in a Web Page Can't Post

Ok, I've finally given up on this one. I have a program that works absolutely fine in my IDE and generates a nice HTML page showing data that I have retrieved from an MS Access database. I'm using a freeware editor/ide- Perl Express. It displays the HTML output fine and even has an option to view the program output in a real Internet Explorer brower. All ok.

But when I try to deploy it and host it on an Apache Server it only partially executes when called from Internet Explorer (ex. http:\\localhost\ For a long time I thought it was my Apache httpd.conf settings but when I thought about it I realized the program was beginning execution because it is showing some of my print statements (as opposed to nothing but an HTTP page errors). It only seems to stop once it gets to the Sql Preparing step. (Btw- I am fairly new to this and still don't know much about oop).

I don't know much about deploying/hosting web pages (this is my first try). I would think you should just be able to dump the in the right area pointed to by the web hosting server (apache in this case), change the settings to allow cgi/pl execution, and simply open a browser to location localhost\

I've dumbed down my program to eliminate all other variables and so I can post it here. The only other thing I can think of is that when you run the program from a real browser it may not have the right permissions to get to the Database. Somebody must have done this before (Displaying database info on a web page using Perl I would think is extremely common). Any help or ideas are appreciated.


# A Test program to connect to a database and display queried result to a web page

use warnings;
use DBI;

$sqlstatement="SELECT ScriptName FROM StationLog";


# Print Initial HTML Page Stuff- Header etc.
print "Content-type: text/html\n\n";
print "<html>\n";
print "<head><title>This is a lame title</title></head>\n";
print "<h3>The program works up to this point</h3>\n";

# Connect to the database
$dbh = DBI->connect("DBI:ODBC:$DB_Name")
or $Conn_Err="True";

print "It makes it this far.\n";

# Query the database
$sth = $dbh->prepare($sqlstatement);
print "But it does not make it this far. Why does program stop?\n";
$sth->execute ||
die "Could not execute SQL statement, maybe invalid?";

# Collect database query results
while (@row=$sth->fetchrow_array)
{ push @results, @row }

# Print out the results in HTML
print "<h4>The Error condition is $Conn_Err</h4>\n";
print "<h4>The Scriptname is $results[0]</h4>\n";

# Print finishing HTML page stuff
print "</body>\n";
print "</html>\n";

# ----- END OF MAIN ROUTINE -----


Apr 30, 2008, 11:27 AM

Post #2 of 2 (5008 views)
Re: [blueston] DBI program works in IDE but not in a Web Page [In reply to] Can't Post

First thing to do is check the apache error log for any errors/warnings related to running that perl script.


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives