I'm working on an API that pulls data from a Drupal site. Everything has gone pretty well I normally use Drupal Bootstrap to load Drupal use the functions I need then spit out a JSON array. I am having one issue though with a module, for some reason Drupal's schema doesn't seem to think the table exists. The module I am working with is VotingApi.

So in my API call I connect to the drupal db. Then if I run:


I get a big list of modules installed and votingapi is included. If I run:


I get a true response. I can also run:


And get a true response. However if I run:


The votingapi_vote and votingapi_cache tables don't show up in the list. So then when I try to write a record to those tables with drupal_write_record() it doesn't work because that function checks the schema to see if the table exists. I have tried clearing the schema cache like this before I call drupal_get_complete_schema():

cache_clear_all('schema', 'cache');

It doesn't help, when it is rebuilt from the API the voting tables never show up. If I go into Drupal's admin and Clear All Cache then the table schema is rebuilt correctly and includes the voting tables. Any ideas on how I can get the schema to rebuild correct for the API?


Figured it out. It had to do with using MultiSite apparently when you use multisite and bootstrap it will only bootstrap to the main site. I found an article talking about it here https://drupal.org/node/2080819

Basically you need to override what the system variable is for the url so that it will bootstrap to the correct site.

define('DRUPAL_ROOT', '/path/to/drupal');
require_once DRUPAL_ROOT . '/includes/bootstrap.inc';
$variables['url'] = 'http://subsite1.example.com/';
  • Really interesting, thanks for sharing your solution
    – Clive
    Feb 24 '14 at 15:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.