<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
  <title>Adding Understanding</title>
  <subtitle>A place for those who add understanding to the world.</subtitle>
  <link rel="alternate" type="text/html" href="http://addingunderstanding.com/drupal-multiple-database-themes.html"/>
  <link rel="self" type="application/atom+xml" href="http://addingunderstanding.com/node/1397/atom/feed"/>
  <id>http://addingunderstanding.com/node/1397/atom/feed</id>
  <updated>2007-07-26T06:00:00-06:00</updated>
  <entry>
    <title>Important order considerations with multiple databases in Drupal</title>
    <link rel="alternate" type="text/html" href="http://addingunderstanding.com/drupal-multiple-database-themes.html" />
    <id>http://addingunderstanding.com/drupal-multiple-database-themes.html</id>
    <published>2007-07-26T06:00:00-06:00</published>
    <updated>2007-07-26T06:00:00-06:00</updated>
    <author>
      <name>joshb</name>
    </author>
    <category term="Drupal" />
    <summary type="html"><![CDATA[<p>I have been working recently with a <a href="http://drupal.org">Drupal</a> application where it is necessary to bring in some data from a non-Drupal database. Eventually these features might roll into a module and the data may move into Drupal but for the moment it sits alone in another database.</p>
<p>An hour or so today disappeared into trying to figure out why various theme_ functions did not work properly. Calling theme('item_list', $list); for example returned broken pages and error messages in the log. After searching for what I was doing wrong in calling theme_ it finally hit me that the error log messages were complaining about not finding the system table and not having parts of the theme. From there it was quick to find the information (which I posted as a <a href="http://drupal.org/node/18429#comment-255400">comment</a> as well).</p>
<p>The upshot is you have to return to the 'default' database before doing theme work. Read the full version for a code examples.</p>
    ]]></summary>
    <content type="html"><![CDATA[<p>I have been working recently with a <a href="http://drupal.org">Drupal</a> application where it is necessary to bring in some data from a non-Drupal database. Eventually these features might roll into a module and the data may move into Drupal but for the moment it sits alone in another database.</p>
<p>An hour or so today disappeared into trying to figure out why various theme_ functions did not work properly. Calling theme('item_list', $list); for example returned broken pages and error messages in the log. After searching for what I was doing wrong in calling theme_ it finally hit me that the error log messages were complaining about not finding the system table and not having parts of the theme. From there it was quick to find the information (which I posted as a <a href="http://drupal.org/node/18429#comment-255400">comment</a> as well).</p>
<p>The upshot is you have to return to the 'default' database before doing theme work. Read the full version for a code examples. </p>
<p>For example this doesn't work properly:</p>
<div class="codeblock">&lt;?php&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; db_set_active('mydb');&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //Things to do with mydb&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $content .= theme('table', $header, $rows); &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $content .= theme('pager',&nbsp; NULL, 10); &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; db_set_active('default'); &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return $content; ?&gt;</div>
<p>With that you'll get a broken page that doesn't display the theme properly and some errors in your php error log. If, instead you close the connection to 'mydb' before you call the theme functions. So this code <strong>does work</strong>:</p>
<div class="codeblock">&lt;?php&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; db_set_active('mydb');&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //Things to do with mydb&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; db_set_active('default'); &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $content .= theme('table', $header, $rows); &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $content .= theme('pager',&nbsp; NULL, 10); &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return $content; ?&gt;</div>
    ]]></content>
  </entry>
</feed>
