Thak you very much!!!
So, if I understood clearly, I have to never disconnect.

But doesn't it mean that i will leave an opened connection
to MySql when Apache is stopped or my application crashes?
My application is just one of the many on the ISP where I am hosted.
Or I am $dbh->ping-ing the same connection?

Thanks!!!

--- In [EMAIL PROTECTED], Josh Chamas <[EMAIL PROTECTED]> wrote:
> k_berov wrote:
> > Hi all.
> > Could anybody tell me how to setup and handle persistent connections 
> > using DBI::mysql?
> > I am not allowed to use Apache::DBI.
> > I tried:
> > 
> > sub Application_OnStart{
> >             $dbh = DBI->connect(
> >             "DBI:mysql:database=mydatabase","me","mypassword",
> >      {
> >       PrintError => 1, # warn( ) on errors
> >       RaiseError => 0, # don't die on error
> >       AutoCommit => 1, # commit executes immediately
> >      }
> > 
> >             )||     sub{$DBI::errstr;undef $dbh};
> > }
> > 
> 
> Use Script_OnStart, which gets run each script request, since you need
> the database connection initilized per process.  A simple method
might look like:
> 
> use vars qw($dbh);
> sub Script_OnStart {
>     unless($dbh && eval { $dbh->ping }) {
>        $dbh = DBI->connect(...);
>     }
> }
> 
> > 
> > Where to put 
> > 
> >     $Server->RegisterCleanup(sub{if($dbh){$dbh->disconnect} });
> > if the server is restarted or killed
> > 
> 
> Well, if you want the connect to be "persistent", then don't do
> this anywhere.  But if you want the connection disconnected each
> request, then you can do this just after the unless{} block above
> in the Script_OnStart, but then you can get rid of the unless block
> altogether, and just have the DBI->connect part since you are not
> doing persistent connections.
> 
> > Is there a standart way
> > or som tweaking? 
> > 
> 
> I would say that using Apache::DBI is standard, but this is fine too.
> 
> Regards,
> 
> Josh
> 
> ________________________________________________________________________
> Josh Chamas, Founder    | NodeWorks - http://www.nodeworks.com
> Chamas Enterprises Inc. | NodeWorks Directory - http://dir.nodeworks.com
> http://www.chamas.com   | Apache::ASP - http://www.apache-asp.org
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]


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

Reply via email to