You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by "Stathy G. Touloumis" <st...@edventions.com> on 2002/02/06 20:34:47 UTC

Apache::DBI

I thought I saw a posting on how to retrieve an independent database handle
from Apache::DBI  using a certain method call (instead of from the shared
$dbh for the child).  Does anyone know where this documentation may reside
(If it is possible).


Thanks,


RE: Apache::DBI

Posted by "Stathy G. Touloumis" <st...@edventions.com>.
> dbi_connect_method?
>
> from man DBI:
>
> The "dbi_connect_method" attribute can be used to specify which driver
> method should be called to establish
> the connection. The only useful values are 'connect',
> 'connect_cached', or some specialized case like
> 'Apache::DBI::connect' (which is automatically the default when
> running within Apache).
>
> so, basically you can create a connection under Apache::DBI that is
> _not_ cached using 'connect'.

Is that using DBI->connect or Apache::DBI->connect . . .

My understanding is that using Apache::DBI pretty much overrides the
functionality of DBI->connect and returns an existing database handle if it
exists (based on parameters passed to method).

I want to be able to return a cached database handle from a method unless a
certain argument is passed.  If this argument is present I would like to
return an independent database handle for perhaps performing transactions.



Re: Apache::DBI

Posted by clayton cottingham <dr...@telus.net>.
"Stathy G. Touloumis" wrote:
> 
> > I'm not sure what you mean, really, but perhaps you mean
> > dbi_connect_method?
> 
> Did you mean specifying this argument like so ?
> 
> DBI->connect( $driver, $u, $p, { dbi_connect_method=> 'connect' } );
> 
> I will see if this is what I am looking for.  Thanks for the reference : )

this is how i usually do it in startup.pl:

#dont declare DBI!!!!
use Apache::DBI;

# Initialize the database connections for each child
      Apache::DBI->connect_on_init
          ("DBI:mysql:database=Ezines;host=localhost",
           "root","database",
           {
            PrintError => 1, # warn() on errors
            RaiseError => 0, # don't die on error
            AutoCommit => 1, # commit executes immediately
           }
          );

$Apache::DBI::DEBUG = 1;


then in my code i just use DBI as i normally would:


    my $dbh =
      DBI->connect(
       
'dbi:mysql(RaiseError=>1,Taint=>1):dbname=database;host=localhost',
        'username', 'password', );

    my $count = $dbh->selectrow_array( q{
SELECT
count(*)
FROM
Ezines
    },
        {},
    );


      $dbh->disconnect;




if you tail the log file you should see Apache::DBI::DEBUG messages

Re: Apache::DBI

Posted by Geoffrey Young <ge...@modperlcookbook.org>.
"Stathy G. Touloumis" wrote:
> 
> > I'm not sure what you mean, really, but perhaps you mean
> > dbi_connect_method?
> 
> Did you mean specifying this argument like so ?
> 
> DBI->connect( $driver, $u, $p, { dbi_connect_method=> 'connect' } );

yes, you never call Apache::DBI->connect() directly.

> 
> I will see if this is what I am looking for. 

from what you described in your previous email, I would think it is.

> Thanks for the reference : )

sure :)

--Geoff

RE: Apache::DBI

Posted by "Stathy G. Touloumis" <st...@edventions.com>.
> I'm not sure what you mean, really, but perhaps you mean
> dbi_connect_method?

Did you mean specifying this argument like so ?

DBI->connect( $driver, $u, $p, { dbi_connect_method=> 'connect' } );

I will see if this is what I am looking for.  Thanks for the reference : )

Re: Apache::DBI

Posted by Geoffrey Young <ge...@modperlcookbook.org>.
"Stathy G. Touloumis" wrote:
> 
> I thought I saw a posting on how to retrieve an independent database handle
> from Apache::DBI  using a certain method call (instead of from the shared
> $dbh for the child).  Does anyone know where this documentation may reside
> (If it is possible).

I'm not sure what you mean, really, but perhaps you mean
dbi_connect_method?

from man DBI:

The "dbi_connect_method" attribute can be used to specify which driver
method should be called to establish
the connection. The only useful values are 'connect',
'connect_cached', or some specialized case like
'Apache::DBI::connect' (which is automatically the default when
running within Apache).

so, basically you can create a connection under Apache::DBI that is
_not_ cached using 'connect'.

is that what you meant?

--Geoff