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


In reply to Help with Persistent Database Connections by comexos

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.