简体   繁体   中英

Apache::DBI->connect_on_init database connection unused

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?

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'
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM