Re: Make database handle persist in CGI/DBI application?



Your CGI is called for each request and then terminated. There is no way to make the DBI handle persistant. (And by the way, if hiding the handle in a hidden field would work, you would create a security hole large enough for a 747.)

You need a permanently running server for a persistant handle. Think about using FastCGI, Apache::Registry or, if you just have started your application, a mod_perl handler.

Alexander


Mary Anderson wrote:

Hi all,

I am writing a Web app in perl/cgi/dbi which (1) attempts to verify
logins by checking against database user passwords, and (2) follows good
dbi practices by logging the user in once at the beginning of the session
instead of logging in immediately prior to accessing the database.

I am running afoul of CGI parameter passing conventions. I do( and
find) the following

use CGI "standard";
use DBI;

my $dbh;
if ($condition){
$dbh = $DBI:connect($connectionString, $login, $password);
# find connection is successful at this poing

sub fubar{

my $sth=$dbh->prepare($cmd);
# find that $dbh is undefined.

I have tried passing the handle in as a ref parameter, using $dbhRef = /*dbh
(maybe this one was done incorrectly) and tried passing a $dbhRef as a
value on a hidden textfield. None of these work. I tend to get "not an array" when I try to do $$dbhref to dereference the handle.

Is there any way to make the handle persist?
Would I have this trouble if I used Mason?

Thanks in advance,
Mary Anderson




--
Alexander Foken
mailto:alexander@xxxxxxxx http://www.foken.de/alexander/

.



Relevant Pages

  • Re: niranjani
    ... i have to use for we enabled work using html for that which cgi version ... tp be used and only dbi module is enough or else dbd:odbc also required ... How do I install DBI on Windows for Perl 5.6.1? ...
    (perl.dbi.users)
  • Re: new CGI::Session creates a new session every visit. GRRR!!!
    ... it seems to be something screwy with a combination of DBI and global ... my $cgi = new CGI; ... I want my $cgi and $session variables to be ...
    (comp.lang.perl.misc)
  • RE: How to track the success of insert
    ... > How will I track if the insertion is success or not? ... > use CGI; ... > use DBI; ... Put your instert inside a transaction like this: ...
    (perl.beginners)
  • Re: new CGI::Session creates a new session every visit. GRRR!!!
    ... it seems to be something screwy with a combination of DBI and global ... my $cgi = new CGI; ... I want my $cgi and $session variables to be ...
    (comp.lang.perl.misc)