Hello,
New release of Helicon Ape has come out right after winter holidays. We wanted to fix a few found bugs and satisfy users’ feature requests. However we also had a desire to bring something new and useful. So here you go—Helicon Ape v3.0.0.30 obtained database functionality. This means Ape has a potential to work with almost any RDBMS. Let’s
provide you with a little explanation. Please note, this article isn’t aimed to give you deep technical information or instruction steps. If you want these please consider “mod_dbd: Saying technically” and “How to connect mod_dbd with various databases”.
mod_dbd
As well as Apache, Ape uses mod_dbd module as an interface to databases. The module organizes interaction between Ape and database drivers through which Ape modules may operate.
Though such database-driven modules are going to be your tools for doing some magic stuff on your server, you should configure mod_dbd to specify database driver, connection options and setup connection pooling. “How to connect mod_dbd with various databases” article will help you in this. Here are the basic features of mod_dbd:
- Compatibility with original Apache mod_dbd module;
- Configurable connection pooling which allows organizing connections in a very efficient way;
- Native support for Microsoft SQL Server and Oracle;
- ODBC and OLEDB interfaces support;
- Possibility to load any ADO.NET compatible connector.
The following sections describe the modules we have already bound with mod_dbd.
mod_authn_dbd
This module is basically the same as mod_authn_file. The only difference as you may guess is that mod_authn_dbd retrieves credentials from a database. To make it working you should specify an SQL query because we don’t know your database structure and it’s not supposed to be limited to mod_authn_dbd needs.
The configuration below demonstrates 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"
As you may notice the code starts with two mod_dbd directives—DBDriver and DBDParams. Both are required for mod_dbd to work correctly, whereas others may be omitted.
These mod_dbd directives are needed to specify desired database driver and connection string. In the example above we’re connecting to Microsoft SQL Server. AuthBasicProvider dbd points to database-based authentication and finally SQL query is set through a special mod_authn_dbd directive AuthDBDUserPWQuery.
Map-files in mod_rewrite
This is probably one of the most exciting features. Before you would tell your web-site engine to regenerate a map-file according to database content. Now you have a possibility to appeal to the database directly and this is very easy to do:
DBDriver mssq
lDBDParams "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]
As opposed to mod_authn_dbd, mod_rewrite doesn’t introduce any special directive for SQL query setup. Instead it uses DBDPrepareSQL which belongs to mod_dbd. DBDPrepareSQL links the query with the unique name and you should use this name in RewriteMap declaration. The rest of the rules should be familiar to you if you worked with map-files before.
Summary
We have considered a brand new feature of Ape—database connectivity. Along with core database module—mod_dbd—we’ve also touched upon mod_authn_dbd and mod_rewrite. Frankly saying this is not a limit and hopefully Ape will have loads of others database-oriented features. We’ll be accumulating customers’ requests and will try and implement the desired functionality. Thanks for your cooperation.
Yours sincerely,
Helicon Tech team.