List:General Discussion« Previous MessageNext Message »
From:Jeff Fillian Date:September 28 2000 9:44pm
Subject:DBI->connect stops html output...why?
View as plain text  
Although I'm not sure I want to admit to being a newby this is my first go
at the Perl DBI and mysql.

For some odd reason I get mixed output from my code and although I've been
reading in the list and tried quite a few things that have been suggested
I'm still bumping my head against a wall.

I will include below code that I used in the telnet session program just to
see if the MySQL server was responding, as well as it's output. And the
modified code I used in my browser session with it's output. The Question
is, why does the output abuptly stop right after the connect statement in
the http session and not in the telnet session.

Someone will ask so here are my software versions:
Perl 5.005.02
Kernel vervion 2.2.14
Linux version 6.0
httpd Apache 1.3.4
MySQL Version - 3.22.32


I have a number of other CGI applications up and running but as soon as I
add the DBI connect.... BOOM!

Thanks so much. BTW it is pretty awesome to see the names of the folk whose
books I've been pouring over keep popping up in these messages. This must be
the place to be.


Thanks,

Jeff Fillian
jaf@stripped


Running under a telnet session and using the following code:

************** BEGIN CODE
********************************************************

#!/usr/bin/perl

use strict;
use DBI;
use CGI;

my $database="WaterPurity";
my $host="localhost";
my $port="3306";
my $mysqlsocket = "/vs2/vs2/fillianc/usr/local/mysql/tmp/mysql.sock";

my $dsn =
"DBI:mysql:database=$database;host=$host;port=$port;mysql_socket=$mysqlsocke
t";
my $user_name = "xxxxx";
my $password = "yyyyy";

my $dbh;

print "before 3\n\n";
print "$dsn\n\n";

$dbh = DBI->connect($dsn, $user_name, $password) or die $DBI::errstr;

my @tables = $dbh->tables();

foreach my $table (@tables) {
 print "Table: $table\n";
}

$dbh->disconnect;

print "after\n\n";

**************** END CODE
*******************************************************

I get the following output.

*************** BEGIN OUTPUT
****************************************************
$ perl txtreg.cgi
before 3

DBI:mysql:database=WaterPurity;host=localhost;port=3306;mysql_socket=/vs2/vs
2/fi
llianc/usr/local/mysql/tmp/mysql.sock

Table: InitialRegistry
after
************* END OUTPUT
*******************************************************

From what I can see here, my MySQL server is running and responding, and I
am getting what I would expect.
Now, when I call a version of this code from my web service using CGI.pm the
output abruptly ends right after the connect statement. Although the version
I'm including here includes calls to CGI.pm, it doesn't seem to matter if I
use CGI.pm or not. You will notice that I am not trying to list tables in
this version, just trying to connect.

********************* CGI CODE *****************************
#!/usr/bin/perl

use strict;
use DBI;
use CGI;

my $database="WaterPurity";
my $host="localhost";
my $port="3306";
my $mysqlsocket = "/vs2/vs2/fillianc/usr/local/mysql/tmp/mysql.sock";

my $dsn =
"DBI:mysql:database=$database;host=$host;port=$port;mysql_socket=$mysqlsocke
t";
my $user_name = "xxxxxxx";
my $password = "yyyyyyy";

my $dbh;

my $q = new CGI;

print $q->header();

print $q->start_html("Jeff");


print $q->p("before 3");
print $q->p("$dsn");

$dbh = DBI->connect($dsn, $user_name, $password) or print
$q->p("$DBI::errstr");

my @tables = $dbh->tables();

$dbh->disconnect;


print $q->p("after");

print $q->end_html();

********************* END HTML CODE ************************************

********************* BROWSER SOURCE OUTPUT ****************************
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
<HTML><HEAD><TITLE>Jeff</TITLE>
</HEAD><BODY><P>before

3</P><P>DBI:mysql:database=WaterPurity;host=localhost;port=3306;mysql_socket
=/vs2/vs2/fillianc/usr/local/mysql/tmp/mysql.sock</P>
********************** END BROWSER SOURCE ******************************

This prints the following in the browser. This at least doesn't tell me that
I have a server configuration error or one of those other frustrating errors
one gets in the browser window.

*********************** BROWSER
OUTPUT****************************************
before 3

DBI:mysql:database=WaterPurity;host=localhost;port=3306;mysql_socket=/vs2/vs
2/fillianc/usr/local/

mysql/tmp/mysql.sock

*********************** END BROWSER OUTPUT
************************************





Thread
DBI->connect stops html output...why?Jeff Fillian28 Sep