Walt Knowles wrote:
> 
> All,
> 
> I'm sure that this is covered somewhere in the documentation or on this
> list, if I could just find the right way to ask the question. So please feel
> free to send me off to read something.
> 
> I currently have a web system with an architecture like this:
> 
> +------------+
> | UI CGI scripts   (foo.pl)
> | using CGI.pm
> +------------+
>      |
>      |
> +------------+
> | Business objects
> | (like documents)
> +------------+
>      |
>      |
> +-------------+
> | Database objects
> | -basically perl
> |  objects on views
> +-------------+
>      |
>      |
> +--------------+
> | Database interface   (db_ora.pm)
> | layer (Oracle now,
> | but soon to have the
> | choice of PostgreSQL
> | or SQLServer)
> +---------------+
>      |
>      |
> +----------------+
> |  DBI/DBD
> +----------------+
> 
> Converting all the globals to Module variables has been a piece of cake, but
> I've run into one big issue. Depending on how you log into the system, the
> user will connect to different databases. When they do this, I store the
> Database Handle from DBI/DBD as $main::dbh. This variable has the scope of
> "the length of processing the request" and then should become undef. Easy
> under normal CGI, because you start with a whole new memory space. If I make
> this a variable in db_ora.pm, it then is persistant "forever"--or until I
> restart apache. If I make it a local in foo.pl, it has the right lifespan,
> but I can't figure out how to address is down in db_ora.pm--particularly
> with it's not just "foo.pl" but 50 different top-level scripts.
> 
> Can someone help? Pointer to documentation? Am I staring at something so
> obvious that it would bite me?
> 
> Thanks in advance,
> 
> Walt Knowles
> 
> #---------------------------------------------------------------------
> #       Walter Knowles          iRepository.net -- Lucidoc (tm)
> #  CEO and Systems Architect  any document               any time
> #    [EMAIL PROTECTED]                  any where
> #     (425) 822-2441  x 1                www.lucidoc.com
> #---------------------------------------------------------------------

I alway call an init routine in my scripts, and this routine must be in
some library. I begun to do this because:

- Persintent database connections are interesting, but if you are using
more than one database server: oracle, postgre and mysql, and you have
many databases in any one of them, you end with dozens of backends
runing all the time killing machine resources. Speed versus memory.

- I found that sometimes wiht postgreSQL the backends abort abnormally,
i put a init routine with this code:

$dbh || $dbh->connect(...);

ensuring that at the init of the script, the database is ok, if it's
already up you don't do nothing.

To finish, i keep the database handle $dbh in a library or Object that
must be "use"d in the script and all the objects or libraries that use
the database directly. This handle must be exported by default by the
library.


Hans Poo

Reply via email to