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