You are viewing a plain text version of this content. The canonical link for it is here.
Posted to embperl@perl.apache.org by "John P. Gibbons" <jo...@dashing.com> on 2004/07/14 00:07:30 UTC

Is there a point in using the request object for db connections when using Apache::DBI?

I was reading this article: 
http://www.perl.com/pub/a/2001/03/embperl.html and of course this 
mailing list and have seen reference to people using the $req object to 
have one database connection.

On my sites I did not do it that way. I use Apache::DBI to handle the 
DBI connection issue and do a separate connects  in my base.html and in 
all other referenced Embperl files/code. Apache::DBI of course makes 
sure we really only have one connection per httpd, as you all know.

I was wondering if there is any benefit or reason to use the request 
object method in my scenario? I'm looking at ways to optimize my code as 
it has grown dramatically and this has been in the back of my mind for 
awhile. I remember reading something that in order to give db access to 
an include embperl file with only subroutines you'd have to use that 
method. But I can't recall now. I was also thinking that there are cases 
when I call .epl files directly and do not want them wrapped in 
base.html. If I were to use the request object method then I would 
either be out of luck or would have to code around it somehow.

I think I've made a lot of mistakes in the techniques I've used to 
develop my core site software and I'd like to correct them.

Does anyone have any thoughts on this?

What's more, is this the appropriate place for these sorts of questions? 
I have an interest in discussing Embperl with other developers who are 
actually making websites and learning about how they did things, etc. 
All I usually see on the list are tech support related discussions. If 
this is the wrong place for that, is there another list or site that 
might be better? If not would it be at all interesting if someone 
started one? I'd be open minded to that as a side project. I already 
have a complete content management system and community (with forums, 
user profiles, etc) all written in Embperl. So I could do it in short order.

Cheers,
John


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


Re: Is there a point in using the request object for db connections when using Apache::DBI?

Posted by "Luiz Fernando B. Ribeiro" <lu...@engenhosolucoes.com.br>.
On Tue, 13 Jul 2004 15:07:30 -0700, John P. Gibbons <jo...@dashing.com>
wrote:

> I was reading this article:  
> http://www.perl.com/pub/a/2001/03/embperl.html and of course this  
> mailing list and have seen reference to people using the $req object to  
> have one database connection.
>
> On my sites I did not do it that way. I use Apache::DBI to handle the  
> DBI connection issue and do a separate connects  in my base.html and in  
> all other referenced Embperl files/code. Apache::DBI of course makes  
> sure we really only have one connection per httpd, as you all know.
>
> I was wondering if there is any benefit or reason to use the request  
> object method in my scenario? I'm looking at ways to optimize my code as  
> it has grown dramatically and this has been in the back of my mind for  
> awhile. I remember reading something that in order to give db access to  
> an include embperl file with only subroutines you'd have to use that  
> method. But I can't recall now. I was also thinking that there are cases  
> when I call .epl files directly and do not want them wrapped in  
> base.html. If I were to use the request object method then I would  
> either be out of luck or would have to code around it somehow.

The request object can be useful to share variables across pages during
_that_ request.

For big projects the recommended solution is to abstract the logic and
database operations into a module and let Embperl handle the interface
generation.

If you use EmbperlObject you can instantiate your class in your template
file, usually base.epr, and share the object across the other
pages/components _in that request_ using the request object. I think this
is a better approach than to use global class variables.

Unless you known what you are doing do not use your own namespace across
pages to be able to share variables. The same applies to CLEANUP. Embperl
handles the namespace and encapsulates each page to avoid leaks and
collisions.

I recommend you to read about EmbperlObject since it has many features to
improve your application design.

-- 
Luiz Fernando B. Ribeiro
Engenho Soluções para a Internet
+55 11 4485-0136

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


Re: Is there a point in using the request object for db connections when using Apache::DBI?

Posted by Gerald Richter <ri...@ecos.de>.
Hi,

>
> What's more, is this the appropriate place for these sorts of
> questions?

I think the list is an appropriate place for such a discussion.

Even better would be if the results of such a discussion, becomes a HOWTO or
something similar.

The Embperl web site has the possibility to add things like this and in case
it does not fit, we can enhance the site (there is nothing that could not
made better). I would prefer to have the Embperl website as the central
place for all Embperl knowledge and do discussions on this list.

Gerald


---------------------------------------------------------------------------
Gerald Richter            ecos electronic communication services gmbh
IT-Securitylösungen * Webapplikationen mit Apache/Perl/mod_perl/Embperl

Post:       Tulpenstrasse 5          D-55276 Dienheim b. Mainz
E-Mail:     richter@ecos.de          Voice:   +49 6133 939-122
WWW:        http://www.ecos.de/      Fax:     +49 6133 939-333
---------------------------------------------------------------------------
ECOS BB-5000 Firewall- und IT-Security Appliance: www.bb-5000.info
---------------------------------------------------------------------------


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