You are viewing a plain text version of this content. The canonical link for it is here.
Posted to embperl@perl.apache.org by wo...@basf-ag.de on 2002/07/09 15:54:38 UTC

Questions about embperl_object_app

Hello.

I have some questions about the embperl_object_app.
1. Will that application object called every time if a page is requested?
2. I have a configuration file similar to the configuration file in the web
example that comes with embperl-2.0b8. How can i access the variables
defined there in the webpages?
For example:
config.pl:

sub new {
    my ($self, $req) = @_;
...
$self->{dbdsn} = 'dbi:Oracle:host=dbhost;sid=dbsid';
$self->{dbusr} = 'dbuser';
$self->{dbpwd} = 'secret';


webapp.pl:

$config = Execute({object => 'config.pl', syntax => 'Perl'});
$config->new($req);
$req->{config} = $config;

# so how i understand this
$req->{dbuser} = $req->{config}->{dbusr};
$req->{dbpwd} = $req->{config}->{dbpwd};
$req->{dsn} = $req->{config}->{dbdsn};

$req->{dbh} = DBI->connect("$req->{dsn}", "$req->{dbuser}","req->{dbpwd}");

somepage.epl:
[-
   $req = shift;
   ...
   $sth = $req->{dbh}->prepare($stmt);
   ...
-]

But $req->{dbh} is undefined.

Wolfgang
------------------------------------------------------------------------
Wolfgang Leideck
ONSYS GmbH
Fon: +49 (0)621/60-44104
Fax: +49 (0)621/60-73744
E-Mail: Wolfgang.Leideck@onsys.de



---------------------------------------------------------------------
To unsubscribe, e-mail: embperl-unsubscribe@perl.apache.org
For additional commands, e-mail: embperl-help@perl.apache.org


Re: Questions about embperl_object_app

Posted by Gerald Richter <ri...@ecos.de>.
Hello.
>
> I have some questions about the embperl_object_app.
> 1. Will that application object called every time if a page is requested?

Once for every http request, _not_ for every file you include with Execute

> 2. I have a configuration file similar to the configuration file in the
web
> example that comes with embperl-2.0b8. How can i access the variables
> defined there in the webpages?
> For example:
> config.pl:
>
> sub new {
>     my ($self, $req) = @_;
> ...
> $self->{dbdsn} = 'dbi:Oracle:host=dbhost;sid=dbsid';
> $self->{dbusr} = 'dbuser';
> $self->{dbpwd} = 'secret';
>
>
> webapp.pl:
>

If you have

sub init
    {
    my ($self, $req) = @_ ;

> $config = Execute({object => 'config.pl', syntax => 'Perl'});
> $config->new($req);
> $req->{config} = $config;
>
> # so how i understand this
> $req->{dbuser} = $req->{config}->{dbusr};
> $req->{dbpwd} = $req->{config}->{dbpwd};
> $req->{dsn} = $req->{config}->{dbdsn};
>
> $req->{dbh} = DBI->connect("$req->{dsn}",
"$req->{dbuser}","req->{dbpwd}");
>

typo: missing $ before req->{dbpwd}
you don't need the " " around the three vars. In case you leave it out, the
Perl compiler will catch such typos

> somepage.epl:
> [-
>    $req = shift;
>    ...
>    $sth = $req->{dbh}->prepare($stmt);
>    ...
> -]
>
> But $req->{dbh} is undefined.
>

It is correct and should work

Did you check that the connect work, e.g. write

$req->{dbh} = DBI->connect($req->{dsn}, $req->{dbuser},$req->{dbpwd}) or die
"Cannot connect: $DBI::errstr" ;

Gerald


-------------------------------------------------------------
Gerald Richter    ecos electronic communication services gmbh
Internetconnect * Webserver/-design/-datenbanken * Consulting

Post:       Tulpenstrasse 5         D-55276 Dienheim b. Mainz
E-Mail:     richter@ecos.de         Voice:    +49 6133 925131
WWW:        http://www.ecos.de      Fax:      +49 6133 925152
-------------------------------------------------------------




---------------------------------------------------------------------
To unsubscribe, e-mail: embperl-unsubscribe@perl.apache.org
For additional commands, e-mail: embperl-help@perl.apache.org