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

hello, i just tried to use such a persistent db-connection, but it won't work... when i load the script, it calls the Database-module which opens the db-connection , this works fine... but when i reload the page, or call it with different params, the module first closes the db-connection, then some server-info is printed and after that it reopens the db-conection and prints the rest...
here's my code:

file Database.pm:
=============
package Database; use strict; use warnings; # with or without use Apache::DBI; the result is the same # i also load Apache::DBI in the startup.pl file... use DBI; use DBD::mysql; our (@EXPORT, $dbh); use base qw/Exporter/; @EXPORT = qw($dbh); #BEGIN { print "Content-Type: text/html\n\n"; print "\nopening db connection!\n"; $dbh = DBI->connect('DBI:mysql:dbname', 'user', 'pwd'); #} END { $dbh->disconnect; print "\nshutting down db-conn!\n"; #should not happen... } 1;
file index.cgi:
==========
#!/usr/bin/perl -w use strict; use warnings; use CGI; use Database; print "Content-type: text/html\n\n"; my $q = new CGI; my %params = $q->Vars; my $userid = delete $params{USER}; my $user = $dbh->selectrow_array("select NAME from USER where ID=?", u +ndef, $userid); print "name of the user: $user!";
-----
and here you can see what's happening:
http://www.detonation.org/cgi-perl/comexos/index.cgi?USER=6

hm, has anyone an idea?
thx for help ...

Edited: ~Tue Jan 14 20:13:10 2003 (GMT) by footpad: Retitled and moved to SOPW, per Consideration