<html><head><meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"><title>Connect to a second database</title><meta name="generator" content="DocBook XSL Stylesheets V1.65.1"><link rel="home" href="index.html" title="OpenACS Core Documentation"><link rel="up" href="tutorial-advanced.html" title="Chapter�10.�Advanced Topics"><link rel="previous" href="tutorial-upgrade-scripts.html" title="Writing upgrade scripts"><link rel="next" href="tutorial-future-topics.html" title="Future Topics"><link rel="stylesheet" href="openacs.css" type="text/css"></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><div class="navheader"><a href="http://openacs.org"><img src="/doc/images/alex.jpg" border="0" alt="Alex logo"></a><table width="100%" summary="Navigation header" border="0"><tr><td width="20%" align="left"><a accesskey="p" href="tutorial-upgrade-scripts.html">Prev</a> </td><th width="60%" align="center">Chapter�10.�Advanced Topics</th><td width="20%" align="right"> <a accesskey="n" href="tutorial-future-topics.html">Next</a></td></tr></table><hr></div><div class="sect1" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="tutorial-second-database"></a>Connect to a second database</h2></div></div><div></div></div><p>It is possible to use the OpenACS TCL database API with
    other databases.  In this example, the OpenACS site uses a
    PostGre database, and accesses another PostGre database called
    legacy.</p><div class="orderedlist"><ol type="1"><li><p>Modify config.tcl to accomodate the legacy database, and to
        ensure that the legacy database is not used for standard
        OpenACS queries:</p><pre class="programlisting">ns_section ns/db/pools
ns_param   pool1              "Pool 1"
ns_param   pool2              "Pool 2"
ns_param   pool3              "Pool 3"
ns_param   legacy             "Legacy"

ns_section ns/db/pool/pool1
<span class="emphasis"><em>#Unchanged from default</em></span>
ns_param   maxidle            1000000000
ns_param   maxopen            1000000000
ns_param   connections        5
ns_param   verbose            $debug
ns_param   extendedtableinfo  true
ns_param   logsqlerrors       $debug
if { $database == "oracle" } {
    ns_param   driver             ora8
    ns_param   datasource         {}
    ns_param   user               $db_name
    ns_param   password           $db_password
} else {
    ns_param   driver             postgres
    ns_param   datasource         ${db_host}:${db_port}:${db_name}
    ns_param   user               $db_user
    ns_param   password           ""
}

ns_section ns/db/pool/pool2
<span class="emphasis"><em>#Unchanged from default, removed for clarity</em></span>

ns_section ns/db/pool/pool3
<span class="emphasis"><em>#Unchanged from default, removed for clarity</em></span>

ns_section ns/db/pool/legacy
ns_param   maxidle            1000000000
ns_param   maxopen            1000000000
ns_param   connections        5
ns_param   verbose            $debug
ns_param   extendedtableinfo  true
ns_param   logsqlerrors       $debug
ns_param   driver             postgres
ns_param   datasource         ${db_host}:${db_port}:legacy_db
ns_param   user               legacy_user
ns_param   password           legacy_password


ns_section ns/server/${server}/db
ns_param   pools              *
ns_param   defaultpool        pool1

ns_section ns/server/${server}/acs/database
ns_param database_names [list main legacy]
ns_param pools_main [list pool1 pool2 pool3]
ns_param pools_legacy [list legacy]</pre></li><li><p>To use the legacy database, use the
          <tt class="computeroutput">-dbn</tt> flag for any of the
          <tt class="computeroutput">db_</tt> API calls.  For
          example, suppose there is a table called "foo" in the legacy
          system, with a field "bar".  List "bar" for all records with
          this tcl file:</p><pre class="programlisting">db_foreach -dbn legacy get_bar_query {
  select bar from foo
  limit 10
} {
  ns_write "&lt;br/&gt;$bar"
}</pre></li></ol></div></div><div class="navfooter"><hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="tutorial-upgrade-scripts.html">Prev</a> </td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right"> <a accesskey="n" href="tutorial-future-topics.html">Next</a></td></tr><tr><td width="40%" align="left">Writing upgrade scripts </td><td width="20%" align="center"><a accesskey="u" href="tutorial-advanced.html">Up</a></td><td width="40%" align="right"> Future Topics</td></tr></table><hr><address><a href="mailto:docs@openacs.org">docs@openacs.org</a></address></div><a name="comments"></a><center><a href="http://openacs.org/doc/current/tutorial-second-database.html#comments">View comments on this page at openacs.org</a></center></body></html>