in reply to CGI Application and global variables (from a database)

I assume you are using CGI::Application? If you are then it is pretty darned easy.

Generally you are going to connect to the database in the setup subroutine and you set the param $self->param('mydbh' => DBI->connect('DBI:mysql:appname', 'xxxxx', 'xxxxx')); then in the cgiapp_prerun I do a variety of things including validating sessions and requiring logins etc. You can get the database handle and then set up more global values here, he is a simple cgiapp_prerun I am using right now:

sub cgiapp_prerun { # If user has a session ID then validate it, otherwise get them on +e my $self = shift; my $dbh = $self->param('mydbh'); my $q = $self->query(); my $session_h = new CGI::Session("driver:MySQL", $q, {Handle => $d +bh}); $self->param('up_session' => $session_h); }
Does that help?

jdtoronto

Replies are listed 'Best First'.
Re: Re: CGI Application and global variables (from a database)
by tmaciak (Initiate) on Dec 19, 2003 at 18:35 UTC
    Rock on JD!

    This is *EXACTLY* what I needed.
    Major KUDOS go out to you.
    I just started learning about CGI::Application the past month or two. I am still at the beginning stages and did not see any mention of the cgiapp_prerun in the documentation on CPAN.
    Thanks a bunch!