On Wed, 7 Nov 2001, Eduardo Grosclaude wrote:

> Newbie to Earth! What am I doing wrong? I don't see the difference between my
> module and the Widgets example included in CGI::Application docs.
>
> Am I failing to fulfill any preconditions? What modules do I need to keep
> running into Apache? How can I know which modules are? Is mod_perl required?
>
> Package Bla;
> use base 'CGI::Application';
> use strict;
> use DBI;
>
> I had a setup() doing this, then took it off, then drop it back in:
>
>         $self->param('DBH'=>'');
>
> I have no teardown() implemented. If the user logs in successfully,
> then I do

( $q = $self->query() assumed before this)

>         $self->param('BASE' => $q->param('base'));
>         $self->param('USER' => $q->param('user'));
>         $self->param('PASS' => $q->param('pass'));
>         my $dsrc = "DBI:mysql:".$self->param('BASE');
>         $self->param('DBH' => DBI->connect($dsrc,
>                         $self->param('USER'),
>                         $self->param('PASS'),
>                         {RaiseError=>1}));

This is in setup(), correct? NOT in a run mode? If it is in a run mode,
you're in trouble.

> Then I present a menu along with some statistics from the database,
> all of which works (that is, the connect() has succeeded).
> I understand DBH is now a persistent parameter (as per my $self->param()),
> // IS THIS RIGHT?

Nope. None of these are persistent parameters. As soon as the page
is finished displaying, the script is exited, and the parameters
disappear, as well as the connection implicitly being disconnected.

This just allows you to set stuff in setup() that you can use in a
run_mode. You have to create the connection in setup() EVERY TIME and
disconnect it in teardown() EVERY TIME.

You CAN (as far as I know) use mod_perl and Apache::DBI to "cache" $dbh's.
Apache::DBI overrides DBI->connect() and $dbh->disconnect() in order to
return the same database connection you had previously - but that still
doesn't keep you from needing to DBI->connect() each and every time your
script is executed. mod_perl is not required, however.

>  but as soon as the user chooses anything from the menu, passing
> to another runmode, this fails miserably:
>
>         my $dbh = $self->param('DBH');
>         my $sql = "bla";
>         my $sth = $dbh->prepare($sql) || return $DBI::errstr;
>
> My debugging console says:
>  Can't call method "prepare" without a package or object reference at ...
>
> I seem to be heavily misunderstanding something. Please help! TIA
>

-- 
Curtis Jewell
http://curtis.livejournal.com/        [EMAIL PROTECTED]
http://web.missouri.edu/~csjc05/      [EMAIL PROTECTED]
http://new-york.utica.mission.net/    [EMAIL PROTECTED]


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to