The app is basically for a multi-site system in Drupal so I wrote an API to be the middle man between Drupal and the app. I had issues all along the way trying to get the API to act correctly when boostrapping into Drupal. It seems easy enough but since it was a multisite and sometimes I had to connect to multiple sites in one API call I got some weird results sometimes. After months of fighting with it I finally ran into a problem that I could work around. The main site didn’t have one of the modules installed on it and when I was trying to use the function drupal_write_record() it checks the cached database table schema for the table you are writing a record to. Well it was failing. Even though I was connected to the database for one of the slave sites it didn’t see the table schema for that table. I tried clearing cache, recreating the table schema, and many more things all to no avail. Even went to my trustworthy StackOverflow and asked a question and didn’t even get a comment. Finally after fighting with it for quite a while I tried to think what else would cause it. I finally did a google search for “drupal multisite bootstrap” and found one single page that discussed this. The solution is to tell Drupal which of the sites you are bootstrapping to. Apparently simply selecting the correct database doesn’t do it. So here is the solution:
require_once DRUPAL_ROOT . '/includes/bootstrap.inc';
$variables['url'] = 'http://www.example.com/subsite1';
This fixed not only the current problem I was having but many of the other quirky issues I had come across along the way. So hopefully this will save someone from having days of headaches related to this issue.