Re: Using DBI

[prev] [thread] [next] [Date index for 2004/12/28]

From: Malcolm J Harwood
Subject: Re: Using DBI
Date: 22:09 on 28 Dec 2004
On Tuesday 28 December 2004 04:56 pm, Octavian Rasnita wrote:

> Ok, but I have seen an example in a tutorial where the database is accessed
> with the username, and the password from a startup.pl file exactly like
> this:
>
> Apache::DBI->connect_on_init("DBI:mysql:database=presa;host=localhost",
> "ODBC", undef, {PrintError =>1, RaiseError=>0, AutoCommit => 1});
>
> In what situation can I access the database at the server startup?

The above does not actually access the database.  What it does is tell 
Apache::DBI to make a connection during the initialisation of each child 
process, so that when you later ask for a connection it has one.

This works if you are using the pre-fork MPM (which I understand doesn't work 
well under Win32 due to limitations of NT). 

It would seem that if you are using the worker MPM then it doesn't make a 
connection for each thread, just for the owning process. In which case you 
get the 'shared handle' error you saw.

> I would like to preload the DBI module at the  server startup and to be

Just put "use DBI;" and "use DBD::mysql;" in your startup, that will compile 
and share the source between processes. (Though if you are using single 
process/multi-thread apache on NT, I'm not sure if that gains you much).

> able to create persistent connections in order to make them faster.

That's what Apache::DBI does. It keeps a pool of persistant connections and 
simply hands you one whenever you ask for a new DB handle.

        -- 
        "How wonderful it is that nobody need wait a single moment to
 improve the world."
- Anne Frank, Diary of a Young Girl

-- 
Report problems: http://perl.apache.org/bugs/
Mail list info: http://perl.apache.org/maillist/modperl.html
List etiquette: http://perl.apache.org/maillist/email-etiquette.html

Using DBI
Octavian Rasnita 19:21 on 28 Dec 2004

Re: Using DBI
Stas Bekman 20:51 on 28 Dec 2004

Re: Using DBI
Malcolm J Harwood 21:18 on 28 Dec 2004

Re: Using DBI
Octavian Rasnita 21:56 on 28 Dec 2004

Re: Using DBI
Malcolm J Harwood 22:09 on 28 Dec 2004

Re: Using DBI
Stas Bekman 22:14 on 28 Dec 2004

Re: Using DBI
Randy Kobes 23:15 on 28 Dec 2004

Re: Using DBI
Randy Kobes 23:27 on 28 Dec 2004

Re: Using DBI
Octavian Rasnita 07:46 on 29 Dec 2004

Re: Using DBI
Randy Kobes 16:24 on 29 Dec 2004

Generated at 12:15 on 16 Jan 2005 by mariachi v0.52