>i ask myself what will happen if a script will die befor i do a
>disconnect... will this connection stay alive and will never close?

The connection will be closed. It might be closed gracefully if Perl
destroys objects in the right order. If nothing else, your socket connection
will be closed by the operating system when your script's process
terminates. It is advisable to run ->disconnect if possible, but not
mandatory. Remember you can write sth like:

$SIG{__DIE__} = sub { eval { $dbh->disconnect }; die $_[0]; }

to act as a kind of on-error-unwind mechanism.

>i do often on my scripts a connect on top of the script - befor anything
>start. if now the script die's on users bad input, for e.g. i have not
>implemented a disconnect befor die'ing yet... is this bad? is there
>something special to mod_perl, Apache Perl or PerlIS?

mod_perl: if you're running a script under Apache::Registry and declared the
database handle as a "my" variable, it will be closed as soon as the
"script" terminates (exits the sub it runs in). If you declared the database
handle as a global ("use vars" or "our") then the connection will *not* be
disconnected, but you can reuse it next time through, by writing a construct
like: "our $dbh ||= DBI->connect(....)". This is very primitive connection
pooling, and if that's what you want, you should use Apache::DBI, which will
keep hold of an extra reference to the database handle, so that even after a
"disconnect" the handle is still connected--- but you can just connect to
the database using "my $dbh = DBI->connect()" as normal and Apache::DBI will
automagically reuse the old handle, after checking that it is still alive by
"ping"ing the database (by e.g. doing "select sysdate from dual").

In summary: Perl should look after this sort of thing for you, and the OS
will act as a backstop in some cases. If you're running Perl in a persistent
environment like mod_perl, it's a good idea to get familiar with how Perl
deals with destroying objects, because they're likely to bite you at some
point. (You should difinitely try to get the hang of the differences between
"my", "our" and "local").

HTH

SRH


Please note that:
 
1. This e-mail may constitute privileged information. If you are not the intended 
recipient, you have received this confidential email and any attachments transmitted 
with it in error and you must not disclose, copy, circulate or in any other way use or 
rely on this information.
2. E-mails to and from the company are monitored for operational reasons and in 
accordance with lawful business practices.
3. The contents of this email are those of the individual and do not necessarily 
represent the views of the company.
4. The company does not conclude contracts by email and all negotiations are subject 
to contract.
5. The company accepts no responsibility once an e-mail and any attachments is sent.

http://www.activis.com




This annotation was added by the e-scan service.
http://www.activis.com
----------------------------------------------------------------------------------
This message has been checked for all known viruses by e:)scan.
For further information please contact [EMAIL PROTECTED]

Reply via email to