Normally you connect like this:

-------------8<-------------
use DBI;
my $dbh = DBI->connect($connectionString, $login, $password);

&foo($dbh);

sub foo {
  my $dbh = shift;
  my $sth = $dbh->prepare($cmd);
}
-------------8<-------------

Did you thought about using mod_perl there Apache::AuthDBI and
Apache::DBI for persitent database connections and authification.

Tom


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
> 
> 
> 

Attachment: signature.asc
Description: OpenPGP digital signature

Reply via email to