- Overview
- Installation & Uninstallation
- Local and remote management using IIS 7
- Context and processing order
- Apache compatibility
- Modules
- core functions
- mod_antibot
- mod_asis
- mod_auth_basic
- mod_auth_digest
- mod_authn_anon
- mod_authn_dbd
- mod_authn_default
- mod_authn_file
- mod_authz_default
- mod_authz_groupfile
- mod_authz_host
- mod_authz_user
- mod_cache
- mod_dbd
- mod_deflate
- mod_developer
- mod_dir
- mod_disk_cache
- mod_env
- mod_evasive
- mod_expires
- mod_filter
- mod_gzip
- mod_headers
- mod_hotlink
- mod_linkfreeze
- mod_log_config
- mod_logio
- mod_mem_cache
- mod_mime
- mod_proxy
- mod_replace
- mod_rewrite
- mod_seo
- mod_setenvif
- mod_so
- mod_speling
- mod_usertrack
- mod_xsendfile
- Articles
- Release history
- Troubleshooting
- License agreement
mod_dbd
Overview
mod_dbd
module manages SQL database connections. It provides upon-request database
connections to modules requiring SQL database functions, and takes care of managing databases
with optimal efficiency and scalability.
Quick start
Mod_dbd provides the interface to mod_authn_dbd, which checks user credentials from SQL tables.
The configuration below demonstrates mod_dbd and mod_authn_dbd in action:
DBDriver mssql
DBDParams "Data Source=db_server;Initial Catalog=users_db;Persist Security Info=True;User ID=sa;Password=your_password"
# core authentication and mod_auth_basic configuration
# for mod_authn_dbd
AuthType Basic
AuthName "My Server"
AuthBasicProvider dbd
# core authorization configuration
Require valid-user
# mod_authn_dbd SQL query to authenticate a user
AuthDBDUserPWQuery "SELECT password FROM users_table WHERE user = @USERNAME"
Also mod_dbd allows to define SQL request that can provide rewrite-maps for rewrite rules from SQL database.
DBDriver mssql
DBDParams "Data Source=server;Initial Catalog=database;User ID=user;Password=password"
DBDPrepareSQL "select OriginalURL from seo_mapping where `SEO_URL`=@KEY" seo_map_select
RewriteEngine On
RewriteMap map_dbd dbd:seo_map_select
RewriteCond ${map_dbd:$1|NOT_FOUND} (.*)
RewriteCond %1 !NOT_FOUND
RewriteRule (.+) %1 [L]
Related articles and topics
- mod_dbd: Saying technically
- How to connect mod_dbd with various databases
- Introduction to database functionality of Helicon Ape
- mod_authn_dbd
- mod_rewrite
Connection pooling
mod_dbd supports connection pooling. This feature allows managing connections in a very efficient way by uniting them into connection pools and reusing already created connections many times. It means that connections aren't closed and reopened upon every request, instead they are stored inside a special place—connection pool. mod_dbd provides special directives for connection pooling tweaking, namely DBDExptime , DBDMax , DBDMin and DBDPersist .
Directives
Name | Context | Description |
---|---|---|
DBDExptime | S V D .h | defines keep-alive time for idle connections |
DBDKeep | S V D .h | specifies maximum sustained number of connections |
DBDMax | S V D .h | sets maximum number of connections |
DBDMin | S V D .h | sets minimum number of connections |
DBDParams | S V D .h | stores parameters for database connection |
DBDPersist | S V D .h | tells whether to use persistent connections |
DBDPrepareSQL | S V D .h | defines an SQL prepared statement |
DBDriver | S V D .h | specifies an SQL driver |
DBDExptime
DBDExptime
directive sets the time to keep idle connections alive. The value 0 means that
pooled connections never time out. The directive isn't supported by Oracle database driver.
Syntax
DBDExptime time-in-seconds
Default
DBDExptime 300
DBDKeep
Currently not supported.
Specifies maximum sustained number of connections.
Syntax
DBDKeep number
Default
DBDKeep 2
DBDMax
DBDMax
directive sets the maximum number of connections per a connections pool.
Syntax
DBDMax number
Default
DBDMax 10
DBDMin
DBDMin
directive sets the minimum number of connections per a connections pool.
Syntax
DBDMin number
Default
DBDMin 1
DBDParams
DBDParams
directive sets the parameters for the database connection depending on the
database driver.
Syntax
DBDParams param1=value1[,param2=value2]
DBDPersist
Tells whether to use persistent connections. If
DBDPersist
directive is set to Off, connection pooling is disabled.
A new database connection is opened when requested by a client, and closed immediately on release.
This option is for debugging and low-usage servers.
The default is to enable and use a pool of persistent connections.
Syntax
DBDPersist On|Off
DBDPrepareSQL
DBDPrepareSQL
directive prepares an SQL statement and assigns it a label.
It is useful for modules such as authentication that repeatedly use a single SQL statement
and where it's more efficient to prepare the statement at startup rather than every time it is used.
Syntax
DBDPrepareSQL "SQL statement" label
Example
DBDPrepareSQL "SELECT password FROM users_table WHERE user = john" password_query
DBDriver
DBDriver
directive specifies the driver which should be used to create and maintain database connections.
Syntax
DBDriver name [reference connection object type]
Description
-
name
may take the following values:
-
mssql
—handles connections to Microsoft SQL Server 7.0 or higher. Example:
DBDriver mssql DBDParams "Data Source=server;Initial Catalog=database_name;User ID=user;Password=password"
-
mysql
—handles connections to MySQL. This driver requres MySQL Connector for .NET to be installed. You may find the connector here:
http://dev.mysql.com/downloads/connector/net/
. It's
also required to specify a reference to the connector's library. To do that you should open C:\Windows\assembly and find MySql.Data.dll assembly. Please open its properties and configure mod_dbd using them as follows:
DBDriver mysql "MySql.Data, Version=6.2.2.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d" DBDParams "Data Source=server;Initial Catalog=database_name;User ID=user;Password=password"
-
oracle
—handles connections to Oracle database. Example:
DBDriver oracle DBDParams "Data Source=server;Initial Catalog=database_name;User ID=user;Password=password"
-
odbc
—handles connections to various databases through ODBC interface. Please make sure you have installed an ODBC connector for the database you want to use. Here is an example for MySQL:
DBDriver odbc DBDParams "Driver={MySQL ODBC 5.1 Driver};Server=server;Database=database;User=root;Password=password;"
-
oledb
—handles connections to various databases through OLEDB interface. Please make sure you have installed an OLEDB connector for the database you want to use. Here is an example for MySQL:
DBDriver oledb DBDParams "Driver={Some OleDb provider};Server=server;Database=database;User=user;Password=password;"
-
mssql
—handles connections to Microsoft SQL Server 7.0 or higher. Example:
Connection string is taken from DBDParams directive as you can see in the examples above.