NAME

Apache::DBI - Authenticate via Perl's DBI using a persistent database connection

SYNOPSIS

# Configuration in httpd.conf or srm.conf

PerlModule Apache::DBI

# Authentication in .htaccess

AuthName DBI
AuthType Basic

#authenticate via DBI
PerlAuthenHandler Apache::DBI

PerlSetVar AuthDBIDB     dbname
PerlSetVar AuthDBIUser   username
PerlSetVar AuthDBIAuth   auth
PerlSetVar AuthDBIDriver driver
#DBI->connect(qw(AuthDBIDB AuthDBIUser AuthDBIAuth AuthDBIDriver))

PerlSetVar AuthDBIUserTable table
PerlSetVar AuthDBINameField user
PerlSetVar AuthDBIPasswordField password

<Limit GET POST>
require valid-user
</Limit>

The require directive is limited to 'valid-user' and 'user xxx' (no group support).

# Persistent database connection in CGI script

use Apache::DBI;

$dbh = Apache::DBI->connect(...);

DESCRIPTION

This module consists out of two parts which can be used independently:

it allows the apache server to authenticate against a database and it provides a persistent database connection.

The authentication initiates a persistent database conection, but the persistent database connection can also be used without authentication.

The database access uses Perl's DBI. For supported DBI drivers see:

http://www.hermetica.com/technologia/DBI/

For using the persistent database connection all you really need is to replace DBI with Apache::DBI. When connecting to a database the module looks if a database handle from a previous connect request is already stored. If not, a new connection is established and the handle is stored for later re-use. There is no need to delete the disconnect statements from your code. They won't do anything. If you want to do an explicit disconnect you need to call: Apache::DBI::disconnect($dbh).

The Apache::DBI module still has a limitation: it keeps database connections persistent on a per process basis. The problem is, if a user accesses several times a database during one session, the http requests will be handled very likely by different httpd children. Every child process needs to do its own connect. It would be nice, if all httpd children could share the database handles. I still don't know how to solve this problem. So if anyone knows how to do this, please let me know.

This module plugs in a menu item for Apache::Status. The menu lists the current database connections. It should be considered incomplete because of the limitations explained above. It shows the current database connections for one specific httpd process, the one which happens to serve the current request. Other httpd children might have other database connections.

SEE ALSO

Apache(3), DBI(3)

AUTHORS

The authentication part is taken from Apache::AuthenDBI and rewritten, so that it does not depend anymore on HTTPD.

mod_perl by Doug MacEachern <dougm@osf.org>
DBI by Tim Bunce <Tim.Bunce@ig.co.uk>
Apache::DBI by Edmund Mergl <E.Mergl@bawue.de>