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

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 .


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 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.


DBDExptime time-in-seconds


DBDExptime 300


Currently not supported.

Specifies maximum sustained number of connections.


DBDKeep number


DBDKeep 2


DBDMax directive sets the maximum number of connections per a connections pool.


DBDMax number


DBDMax 10


DBDMin directive sets the minimum number of connections per a connections pool.


DBDMin number


DBDMin 1


DBDParams directive sets the parameters for the database connection depending on the database driver.


DBDParams param1=value1[,param2=value2]


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.


DBDPersist On|Off


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.


DBDPrepareSQL "SQL statement" label


DBDPrepareSQL "SELECT password FROM users_table WHERE user = john" password_query


DBDriver directive specifies the driver which should be used to create and maintain database connections.


DBDriver name [reference connection object type]


  • 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: . 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=, 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;"

Connection string is taken from DBDParams directive as you can see in the examples above.