Lev Lvovsky wrote:
It looks like from reading the docs, that the startup.pl file can handle specifying more than one user for the purpose of making multiple connections with different database accounts.

I'm having a problem in retrieving these cached connections when running the code after server startup. Am I correct in assuming that specifying identical DBI connection parameters in the mod_perl handler as those in the startup.pl connections will return the $dbh of the corresponding cached connection?

In using the 'mysql' client to show a list of connections, I see that in addition to the several cached connections I create upon startup, running a mod_perl handler creates another db connection (not using the cached one).

Any pointers appreciated.
is this mod_perl 1 or 2 ?
Setting $Apache::DBI::Debug = 2; and watching you're error log file
should tell you what its doing.

package X;
# database
our $host = 'mysql.x.y';
our $dsn  = "dbi:mysql:db;host=$host";
our $user = 'u';
our $pass = 'p';
our %db_attrs = (
    RaiseError         => 1,
    PrintError         => 0,
    Taint              => 0,
    AutoCommit         => 1,
    LongReadLen        => 50000,
    LongTruncOk        => 1,
    ShowErrorStatement => 1,
    ChopBlanks         => 1,
    FetchHashKeyName   => "NAME_lc",
);

startup.pl:
use X ();

use Apache::DBI (); ## order matters
use DBI ();  ## this must be the first use of DBI

Apache::DBI->connect_on_init($X::dsn, $X::user, $X::pass,\%X::attrs);

## having made the above comments, you can do this in httpd.conf also
## using PerlModule lines.

package Y;

use X ();
use DBI ();

use Apache2::Log ();
use Apache2::RequestRec ();

sub get_dbh {
    my $r = shift;

    my $dbh = eval {
        DBI->connect($X::dsn, $X::user, $X::pass, \%X:db_attrs)
    };
    $r->log_error($@) if $@;

    return $dbh;
}

package Z;

use Y ();

sub handler {
  my $r = shift;

  my $dbh = Y::get_dbh($r);

  ....
}

What you should end up with is 1 connection per child (assuming prefork)

When you connect, you should get one of those back. If you don't, you're config is screwed, or your parameters are different.

see also the eg/ directory of the Apache-DBI-1.06.tar.gz

HTH


--
------------------------------------------------------------------------
Philip M. Gollucci ([EMAIL PROTECTED]) 323.219.4708
Consultant / http://p6m7g8.net/Resume/resume.shtml
Senior Software Engineer - TicketMaster - http://ticketmaster.com
1024D/A79997FA F357 0FDD 2301 6296 690F  6A47 D55A 7172 A799 97F

I never had a dream come true
'Til the day that I found you.
Even though I pretend that I've moved on
You'll always be my baby.
I never found the words to say
You're the one I think about each day
And I know no matter where life takes me to
A part of me will always be...
A part of me will always be with you.

Reply via email to