<p>This simple example shows use of this module in the context of
the Authentication and DBD frameworks.</p>
<div class="example"><pre>
-#Database Management
+# mod_dbd configuration
+DBDriver pgsql
+DBDParams "dbname=apacheauth user=apache password=xxxxxx"
-#Use the PostgreSQL driver
-<code>DBDriver pgsql</code>
+DBDMin 4
+DBDKeep 8
+DBDMax 20
+DBDExptime 300
-#Connection string: database name and login credentials
-<code>DBDParams "dbname=htpasswd user=apache password=xxxxxx"</code>
+<Directory /usr/www/myhost/private>
+ # core authentication and mod_auth_basic configuration
+ # for mod_authn_dbd
+ AuthType Basic
+ AuthName "My Server"
+ AuthBasicProvider dbd
-#Parameters for Connection Pool Management
-<code>DBDMin 1
-DBDKeep 2
-DBDMax 10
-DBDExptime 60</code>
+ # core authorization configuration
+ Require valid-user
-#Authentication Section
-<code><Directory /usr/www/myhost/private></code>
-
- #mod_auth configuration for authn_dbd
- <code>AuthType Basic
- AuthName "My Server"
- AuthBasicProvider dbd</code>
-
- #authz configuration
- <code>Require valid-user</code>
-
- #SQL query to verify a user
- #(note: DBD drivers recognise both stdio-like %s and native syntax)
- <code>AuthDBDUserPWQuery "select password from authn where username = %s"
-</Directory></code>
+ # mod_authn_dbd SQL query to authenticate a user
+ AuthDBDUserPWQuery \
+ "SELECT password FROM authn WHERE user = %s"
+</Directory>
</pre></div>
</div><div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div>
<div class="section">
<h2><a name="exposed" id="exposed">Exposing Login Information</a></h2>
<p>
-Whenever a query is made to the database server, all columns returned by
-the query are placed in the environment, using environment variables with
-the prefix "AUTHENTICATE_".
+If httpd was built against <a class="glossarylink" href="../glossary.html#apr" title="see glossary">APR</a> version 1.3.0
+or higher, then whenever a query is made to the database server, all
+column values in the first row returned by the query are placed in the
+environment, using environment variables with the prefix "AUTHENTICATE_".
</p>
<p>If a database query for example returned the username, full name
and telephone number of a user, a CGI program will have access to
<tr><th><a href="directive-dict.html#Module">Module:</a></th><td>mod_authn_dbd</td></tr>
</table>
<p>The <code class="directive">AuthDBDUserPWQuery</code> specifies an
- SQL query to look up a password for a specified user.
- The query must take a single string (typically SQL varchar)
- argument (username), and return a single value (encrypted password).
- </p>
- <div class="example"><p><code>
- AuthDBDUserPWQuery "SELECT password FROM authn WHERE username = %s"
- </code></p></div>
- <p>If httpd was built against apr v1.3.0 or higher, any additional
- columns specified in the select statement will be inserted into
- the environment with the name <code>AUTHENTICATE_<COLUMN></code>.
+ SQL query to look up a password for a specified user. The user's ID
+ will be passed as a single string parameter when the SQL query is
+ executed. It may be referenced within the query statement using
+ a <code>%s</code> format specifier.</p>
+ <div class="example"><h3>Example</h3><pre>
+AuthDBDUserPWQuery \
+ "SELECT password FROM authn WHERE user = %s"
+</pre></div>
+ <p>The first column value of the first row returned by the query
+ statement should be a string containing the encrypted password.
+ Subsequent rows will be ignored. If no rows are returned, the user
+ will not be authenticated through <code class="module"><a href="../mod/mod_authn_dbd.html">mod_authn_dbd</a></code>.</p>
+ <p>If httpd was built against <a class="glossarylink" href="../glossary.html#apr" title="see glossary">APR</a> version 1.3.0
+ or higher, any additional column values in the first row returned by
+ the query statement will be stored as environment variables with
+ names of the form <code>AUTHENTICATE_<var>COLUMN</var></code>.
</p>
</div>
</table>
<p>The <code class="directive">AuthDBDUserRealmQuery</code> specifies an
SQL query to look up a password for a specified user and realm.
- The query must take two string (typically SQL varchar) arguments
- (username and realm), and return a single value (encrypted password).
- </p>
- <div class="example"><p><code>
- AuthDBDUserRealmQuery "SELECT password FROM authn
- WHERE username = %s AND realm = %s"
- </code></p></div>
- <p>If httpd was built against apr v1.3.0 or higher, any additional
- columns specified in the select statement will be inserted into
- the environment with the name <code>AUTHENTICATE_<COLUMN></code>.
+ The user's ID and the realm, in that order, will be passed as string
+ parameters when the SQL query is executed. They may be referenced
+ within the query statement using <code>%s</code> format specifiers.</p>
+ <div class="example"><h3>Example</h3><pre>
+AuthDBDUserRealmQuery \
+ "SELECT password FROM authn WHERE user = %s AND realm = %s"
+</pre></div>
+ <p>The first column value of the first row returned by the query
+ statement should be a string containing the encrypted password.
+ Subsequent rows will be ignored. If no rows are returned, the user
+ will not be authenticated through <code class="module"><a href="../mod/mod_authn_dbd.html">mod_authn_dbd</a></code>.</p>
+ <p>If httpd was built against <a class="glossarylink" href="../glossary.html#apr" title="see glossary">APR</a> version 1.3.0
+ or higher, any additional column values in the first row returned by
+ the query statement will be stored as environment variables with
+ names of the form <code>AUTHENTICATE_<var>COLUMN</var></code>.
</p>
-
</div>
</div>
<div class="bottomlang">
<h3>Summary</h3>
<p><code class="module"><a href="../mod/mod_dbd.html">mod_dbd</a></code> manages SQL database connections using
- <a href="http://people.apache.org/~niq/dbd.html">apr_dbd</a>.
- It provides database connections on request to modules
- requiring SQL database functions, and takes care of
+ <a class="glossarylink" href="../glossary.html#apr" title="see glossary">APR</a>. It provides database connections on request
+ to modules requiring SQL database functions, and takes care of
managing databases with optimal efficiency and scalability
- for both threaded and non-threaded MPMs.</p>
+ for both threaded and non-threaded MPMs. For details, see the
+ <a href="http://apr.apache.org/">APR</a> website and this overview of the
+ <a href="http://people.apache.org/~niq/dbd.html">Apache DBD Framework</a>
+ by its original developer.
+</p>
</div>
<div id="quickview"><h3 class="directives">Directives</h3>
<ul id="toc">
classic LAMP (Linux, Apache, Mysql, Perl/PHP/Python).
On threaded platform, it provides an altogether more
scalable and efficient <em>connection pool</em>, as
- described in <a href="http://www.apachetutor.org/dev/reslist">this article at ApacheTutor</a>. <code class="module"><a href="../mod/mod_dbd.html">mod_dbd</a></code> supersedes
- the modules presented in that article.</p>
+ described in <a href="http://www.apachetutor.org/dev/reslist">this
+ article at ApacheTutor</a>. Note that <code class="module"><a href="../mod/mod_dbd.html">mod_dbd</a></code>
+ supersedes the modules presented in that article.</p>
</div><div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div>
<div class="section">
<h2><a name="API" id="API">Apache DBD API</a></h2>