Re: Using DBI

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

From: Randy Kobes
Subject: Re: Using DBI
Date: 23:15 on 28 Dec 2004
On Tue, 28 Dec 2004, 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?
>
> I would like to preload the DBI module at the  server startup and to be able
> to create persistent connections in order to make them faster.

It looks from some comments in the latest Apache::DBI
(version 0.94) that the connect_on_init method hasn't been
completely ported to mod_perl 2 yet. Can you try the
following patch against Apache::DBI (version 0.94) - if
you're using ppm on Win32, you can get this from the
Apache-DBI.ppd package in the
   http://theoryx5.uwinnipeg.ca/ppms/
repository.

==============================================================
--- DBI.pm~	Tue Feb 17 18:18:50 2004
+++ DBI.pm	Tue Dec 28 16:43:46 2004
@@ -13,7 +13,7 @@

 # 1: report about new connect
 # 2: full debug output
-$Apache::DBI::DEBUG = 0;
+$Apache::DBI::DEBUG = 2;
 #DBI->trace(2);

 my %Connected;    # cache for database handles
@@ -23,6 +23,8 @@
 my %LastPingTime; # keeps track of last ping per data_source
 my $Idx;          # key of %Connected and %Rollback.

+use Apache::ServerUtil ();
+my $s = Apache->server;

 # supposed to be called in a startup script.
 # stores the data_source of all connections, which are supposed to be created upon
@@ -32,9 +34,8 @@
     # provide a handler which creates all connections during server startup

     # TODO - Should check for mod_perl 2 and do the right thing there
-    carp "Apache.pm was not loaded\n" and return unless $INC{'Apache.pm'};
-    if(!@ChildConnect and Apache->can('push_handlers')) {
-        Apache->push_handlers(PerlChildInitHandler => \&childinit);
+    if(!@ChildConnect) {
+        $s->push_handlers(PerlChildInitHandler => \&childinit);
     }
     # store connections
     push @ChildConnect, [@_];
@@ -96,7 +97,7 @@
     # TODO - Fix mod_perl 2.0 here
     if(!$Rollback{$Idx} and $needCleanup and Apache->can('push_handlers')) {
         print STDERR "$prefix push PerlCleanupHandler \n" if $Apache::DBI::DEBUG > 1;
-        Apache->push_handlers("PerlCleanupHandler", \&cleanup);
+        $s->push_handlers("PerlCleanupHandler", \&cleanup);
         # make sure, that the rollback is called only once for every
         # request, even if the script calls connect more than once
         $Rollback{$Idx} = 1;

====================================================================================

Does this help?

        -- 
        best regards,
randy kobes

-- 
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