Apache::DBI->connect_on_init database connection unused

207 views Asked by At

I have mod perl 2 code that is doing Apache::DBI->connect_on_init($dsn, $user, $passwd); in a script loaded by PerlRequire.

But when processing a request, doing DBI->connect_cached($dsn, $user, $passwd) is creating an additional connection, not using the one created at child init. (DBI is used instead of Apache::DBI because that code is also used in non-apache contexts.)

How do I make it use the already cached connection?

1

There are 1 answers

0
ysth On BEST ANSWER

Setting $Apache::DBI::DEBUG=2 shows that the connection created by DBI has an extra attribute set; adding that attribute to the connect_on_init call makes the cached connection be reused:

Apache::DBI->connect_on_init($dsn, $user, $passwd, {
    dbi_connect_method => 'Apache::DBI::connect'
});